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. On XCOFF, default visibility means no explicit 485 visibility bit will be set and whether the symbol is visible 486 (i.e "exported") to other modules depends primarily on export lists 487 provided to the linker. Default visibility corresponds to "external 488 linkage" in the language. 489"``hidden``" - Hidden style 490 Two declarations of an object with hidden visibility refer to the 491 same object if they are in the same shared object. Usually, hidden 492 visibility indicates that the symbol will not be placed into the 493 dynamic symbol table, so no other module (executable or shared 494 library) can reference it directly. 495"``protected``" - Protected style 496 On ELF, protected visibility indicates that the symbol will be 497 placed in the dynamic symbol table, but that references within the 498 defining module will bind to the local symbol. That is, the symbol 499 cannot be overridden by another module. 500 501A symbol with ``internal`` or ``private`` linkage must have ``default`` 502visibility. 503 504.. _dllstorageclass: 505 506DLL Storage Classes 507------------------- 508 509All Global Variables, Functions and Aliases can have one of the following 510DLL storage class: 511 512``dllimport`` 513 "``dllimport``" causes the compiler to reference a function or variable via 514 a global pointer to a pointer that is set up by the DLL exporting the 515 symbol. On Microsoft Windows targets, the pointer name is formed by 516 combining ``__imp_`` and the function or variable name. 517``dllexport`` 518 On Microsoft Windows targets, "``dllexport``" causes the compiler to provide 519 a global pointer to a pointer in a DLL, so that it can be referenced with the 520 ``dllimport`` attribute. the pointer name is formed by combining ``__imp_`` 521 and the function or variable name. On XCOFF targets, ``dllexport`` indicates 522 that the symbol will be made visible to other modules using "exported" 523 visibility and thus placed by the linker in the loader section symbol table. 524 Since this storage class exists for defining a dll interface, the compiler, 525 assembler and linker know it is externally referenced and must refrain from 526 deleting the symbol. 527 528.. _tls_model: 529 530Thread Local Storage Models 531--------------------------- 532 533A variable may be defined as ``thread_local``, which means that it will 534not be shared by threads (each thread will have a separated copy of the 535variable). Not all targets support thread-local variables. Optionally, a 536TLS model may be specified: 537 538``localdynamic`` 539 For variables that are only used within the current shared library. 540``initialexec`` 541 For variables in modules that will not be loaded dynamically. 542``localexec`` 543 For variables defined in the executable and only used within it. 544 545If no explicit model is given, the "general dynamic" model is used. 546 547The models correspond to the ELF TLS models; see `ELF Handling For 548Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for 549more information on under which circumstances the different models may 550be used. The target may choose a different TLS model if the specified 551model is not supported, or if a better choice of model can be made. 552 553A model can also be specified in an alias, but then it only governs how 554the alias is accessed. It will not have any effect in the aliasee. 555 556For platforms without linker support of ELF TLS model, the -femulated-tls 557flag can be used to generate GCC compatible emulated TLS code. 558 559.. _runtime_preemption_model: 560 561Runtime Preemption Specifiers 562----------------------------- 563 564Global variables, functions and aliases may have an optional runtime preemption 565specifier. If a preemption specifier isn't given explicitly, then a 566symbol is assumed to be ``dso_preemptable``. 567 568``dso_preemptable`` 569 Indicates that the function or variable may be replaced by a symbol from 570 outside the linkage unit at runtime. 571 572``dso_local`` 573 The compiler may assume that a function or variable marked as ``dso_local`` 574 will resolve to a symbol within the same linkage unit. Direct access will 575 be generated even if the definition is not within this compilation unit. 576 577.. _namedtypes: 578 579Structure Types 580--------------- 581 582LLVM IR allows you to specify both "identified" and "literal" :ref:`structure 583types <t_struct>`. Literal types are uniqued structurally, but identified types 584are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used 585to forward declare a type that is not yet available. 586 587An example of an identified structure specification is: 588 589.. code-block:: llvm 590 591 %mytype = type { %mytype*, i32 } 592 593Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only 594literal types are uniqued in recent versions of LLVM. 595 596.. _nointptrtype: 597 598Non-Integral Pointer Type 599------------------------- 600 601Note: non-integral pointer types are a work in progress, and they should be 602considered experimental at this time. 603 604LLVM IR optionally allows the frontend to denote pointers in certain address 605spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`. 606Non-integral pointer types represent pointers that have an *unspecified* bitwise 607representation; that is, the integral representation may be target dependent or 608unstable (not backed by a fixed integer). 609 610``inttoptr`` and ``ptrtoint`` instructions have the same semantics as for 611integral (i.e. normal) pointers in that they convert integers to and from 612corresponding pointer types, but there are additional implications to be 613aware of. Because the bit-representation of a non-integral pointer may 614not be stable, two identical casts of the same operand may or may not 615return the same value. Said differently, the conversion to or from the 616non-integral type depends on environmental state in an implementation 617defined manner. 618 619If the frontend wishes to observe a *particular* value following a cast, the 620generated IR must fence with the underlying environment in an implementation 621defined manner. (In practice, this tends to require ``noinline`` routines for 622such operations.) 623 624From the perspective of the optimizer, ``inttoptr`` and ``ptrtoint`` for 625non-integral types are analogous to ones on integral types with one 626key exception: the optimizer may not, in general, insert new dynamic 627occurrences of such casts. If a new cast is inserted, the optimizer would 628need to either ensure that a) all possible values are valid, or b) 629appropriate fencing is inserted. Since the appropriate fencing is 630implementation defined, the optimizer can't do the latter. The former is 631challenging as many commonly expected properties, such as 632``ptrtoint(v)-ptrtoint(v) == 0``, don't hold for non-integral types. 633 634.. _globalvars: 635 636Global Variables 637---------------- 638 639Global variables define regions of memory allocated at compilation time 640instead of run-time. 641 642Global variable definitions must be initialized. 643 644Global variables in other translation units can also be declared, in which 645case they don't have an initializer. 646 647Global variables can optionally specify a :ref:`linkage type <linkage>`. 648 649Either global variable definitions or declarations may have an explicit section 650to be placed in and may have an optional explicit alignment specified. If there 651is a mismatch between the explicit or inferred section information for the 652variable declaration and its definition the resulting behavior is undefined. 653 654A variable may be defined as a global ``constant``, which indicates that 655the contents of the variable will **never** be modified (enabling better 656optimization, allowing the global data to be placed in the read-only 657section of an executable, etc). Note that variables that need runtime 658initialization cannot be marked ``constant`` as there is a store to the 659variable. 660 661LLVM explicitly allows *declarations* of global variables to be marked 662constant, even if the final definition of the global is not. This 663capability can be used to enable slightly better optimization of the 664program, but requires the language definition to guarantee that 665optimizations based on the 'constantness' are valid for the translation 666units that do not include the definition. 667 668As SSA values, global variables define pointer values that are in scope 669(i.e. they dominate) all basic blocks in the program. Global variables 670always define a pointer to their "content" type because they describe a 671region of memory, and all memory objects in LLVM are accessed through 672pointers. 673 674Global variables can be marked with ``unnamed_addr`` which indicates 675that the address is not significant, only the content. Constants marked 676like this can be merged with other constants if they have the same 677initializer. Note that a constant with significant address *can* be 678merged with a ``unnamed_addr`` constant, the result being a constant 679whose address is significant. 680 681If the ``local_unnamed_addr`` attribute is given, the address is known to 682not be significant within the module. 683 684A global variable may be declared to reside in a target-specific 685numbered address space. For targets that support them, address spaces 686may affect how optimizations are performed and/or what target 687instructions are used to access the variable. The default address space 688is zero. The address space qualifier must precede any other attributes. 689 690LLVM allows an explicit section to be specified for globals. If the 691target supports it, it will emit globals to the section specified. 692Additionally, the global can placed in a comdat if the target has the necessary 693support. 694 695External declarations may have an explicit section specified. Section 696information is retained in LLVM IR for targets that make use of this 697information. Attaching section information to an external declaration is an 698assertion that its definition is located in the specified section. If the 699definition is located in a different section, the behavior is undefined. 700 701By default, global initializers are optimized by assuming that global 702variables defined within the module are not modified from their 703initial values before the start of the global initializer. This is 704true even for variables potentially accessible from outside the 705module, including those with external linkage or appearing in 706``@llvm.used`` or dllexported variables. This assumption may be suppressed 707by marking the variable with ``externally_initialized``. 708 709An explicit alignment may be specified for a global, which must be a 710power of 2. If not present, or if the alignment is set to zero, the 711alignment of the global is set by the target to whatever it feels 712convenient. If an explicit alignment is specified, the global is forced 713to have exactly that alignment. Targets and optimizers are not allowed 714to over-align the global if the global has an assigned section. In this 715case, the extra alignment could be observable: for example, code could 716assume that the globals are densely packed in their section and try to 717iterate over them as an array, alignment padding would break this 718iteration. The maximum alignment is ``1 << 32``. 719 720For global variables declarations, as well as definitions that may be 721replaced at link time (``linkonce``, ``weak``, ``extern_weak`` and ``common`` 722linkage types), LLVM makes no assumptions about the allocation size of the 723variables, except that they may not overlap. The alignment of a global variable 724declaration or replaceable definition must not be greater than the alignment of 725the definition it resolves to. 726 727Globals can also have a :ref:`DLL storage class <dllstorageclass>`, 728an optional :ref:`runtime preemption specifier <runtime_preemption_model>`, 729an optional :ref:`global attributes <glattrs>` and 730an optional list of attached :ref:`metadata <metadata>`. 731 732Variables and aliases can have a 733:ref:`Thread Local Storage Model <tls_model>`. 734 735:ref:`Scalable vectors <t_vector>` cannot be global variables or members of 736arrays because their size is unknown at compile time. They are allowed in 737structs to facilitate intrinsics returning multiple values. Structs containing 738scalable vectors cannot be used in loads, stores, allocas, or GEPs. 739 740Syntax:: 741 742 @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility] 743 [DLLStorageClass] [ThreadLocal] 744 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] 745 [ExternallyInitialized] 746 <global | constant> <Type> [<InitializerConstant>] 747 [, section "name"] [, partition "name"] 748 [, comdat [($name)]] [, align <Alignment>] 749 [, no_sanitize_address] [, no_sanitize_hwaddress] 750 [, sanitize_address_dyninit] [, sanitize_memtag] 751 (, !name !N)* 752 753For example, the following defines a global in a numbered address space 754with an initializer, section, and alignment: 755 756.. code-block:: llvm 757 758 @G = addrspace(5) constant float 1.0, section "foo", align 4 759 760The following example just declares a global variable 761 762.. code-block:: llvm 763 764 @G = external global i32 765 766The following example defines a thread-local global with the 767``initialexec`` TLS model: 768 769.. code-block:: llvm 770 771 @G = thread_local(initialexec) global i32 0, align 4 772 773.. _functionstructure: 774 775Functions 776--------- 777 778LLVM function definitions consist of the "``define``" keyword, an 779optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption 780specifier <runtime_preemption_model>`, an optional :ref:`visibility 781style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, 782an optional :ref:`calling convention <callingconv>`, 783an optional ``unnamed_addr`` attribute, a return type, an optional 784:ref:`parameter attribute <paramattrs>` for the return type, a function 785name, a (possibly empty) argument list (each with optional :ref:`parameter 786attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`, 787an optional address space, an optional section, an optional partition, 788an optional alignment, an optional :ref:`comdat <langref_comdats>`, 789an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`, 790an optional :ref:`prologue <prologuedata>`, 791an optional :ref:`personality <personalityfn>`, 792an optional list of attached :ref:`metadata <metadata>`, 793an opening curly brace, a list of basic blocks, and a closing curly brace. 794 795Syntax:: 796 797 define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass] 798 [cconv] [ret attrs] 799 <ResultType> @<FunctionName> ([argument list]) 800 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs] 801 [section "name"] [partition "name"] [comdat [($name)]] [align N] 802 [gc] [prefix Constant] [prologue Constant] [personality Constant] 803 (!name !N)* { ... } 804 805The argument list is a comma separated sequence of arguments where each 806argument is of the following form: 807 808Syntax:: 809 810 <type> [parameter Attrs] [name] 811 812LLVM function declarations consist of the "``declare``" keyword, an 813optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style 814<visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an 815optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr`` 816or ``local_unnamed_addr`` attribute, an optional address space, a return type, 817an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly 818empty list of arguments, an optional alignment, an optional :ref:`garbage 819collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional 820:ref:`prologue <prologuedata>`. 821 822Syntax:: 823 824 declare [linkage] [visibility] [DLLStorageClass] 825 [cconv] [ret attrs] 826 <ResultType> @<FunctionName> ([argument list]) 827 [(unnamed_addr|local_unnamed_addr)] [align N] [gc] 828 [prefix Constant] [prologue Constant] 829 830A function definition contains a list of basic blocks, forming the CFG (Control 831Flow Graph) for the function. Each basic block may optionally start with a label 832(giving the basic block a symbol table entry), contains a list of instructions, 833and ends with a :ref:`terminator <terminators>` instruction (such as a branch or 834function return). If an explicit label name is not provided, a block is assigned 835an implicit numbered label, using the next value from the same counter as used 836for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a 837function entry block does not have an explicit label, it will be assigned label 838"%0", then the first unnamed temporary in that block will be "%1", etc. If a 839numeric label is explicitly specified, it must match the numeric label that 840would be used implicitly. 841 842The first basic block in a function is special in two ways: it is 843immediately executed on entrance to the function, and it is not allowed 844to have predecessor basic blocks (i.e. there can not be any branches to 845the entry block of a function). Because the block can have no 846predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`. 847 848LLVM allows an explicit section to be specified for functions. If the 849target supports it, it will emit functions to the section specified. 850Additionally, the function can be placed in a COMDAT. 851 852An explicit alignment may be specified for a function. If not present, 853or if the alignment is set to zero, the alignment of the function is set 854by the target to whatever it feels convenient. If an explicit alignment 855is specified, the function is forced to have at least that much 856alignment. All alignments must be a power of 2. 857 858If the ``unnamed_addr`` attribute is given, the address is known to not 859be significant and two identical functions can be merged. 860 861If the ``local_unnamed_addr`` attribute is given, the address is known to 862not be significant within the module. 863 864If an explicit address space is not given, it will default to the program 865address space from the :ref:`datalayout string<langref_datalayout>`. 866 867.. _langref_aliases: 868 869Aliases 870------- 871 872Aliases, unlike function or variables, don't create any new data. They 873are just a new symbol and metadata for an existing position. 874 875Aliases have a name and an aliasee that is either a global value or a 876constant expression. 877 878Aliases may have an optional :ref:`linkage type <linkage>`, an optional 879:ref:`runtime preemption specifier <runtime_preemption_model>`, an optional 880:ref:`visibility style <visibility>`, an optional :ref:`DLL storage class 881<dllstorageclass>` and an optional :ref:`tls model <tls_model>`. 882 883Syntax:: 884 885 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee> 886 [, partition "name"] 887 888The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``, 889``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers 890might not correctly handle dropping a weak symbol that is aliased. 891 892Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as 893the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point 894to the same content. 895 896If the ``local_unnamed_addr`` attribute is given, the address is known to 897not be significant within the module. 898 899Since aliases are only a second name, some restrictions apply, of which 900some can only be checked when producing an object file: 901 902* The expression defining the aliasee must be computable at assembly 903 time. Since it is just a name, no relocations can be used. 904 905* No alias in the expression can be weak as the possibility of the 906 intermediate alias being overridden cannot be represented in an 907 object file. 908 909* No global value in the expression can be a declaration, since that 910 would require a relocation, which is not possible. 911 912* If either the alias or the aliasee may be replaced by a symbol outside the 913 module at link time or runtime, any optimization cannot replace the alias with 914 the aliasee, since the behavior may be different. The alias may be used as a 915 name guaranteed to point to the content in the current module. 916 917.. _langref_ifunc: 918 919IFuncs 920------- 921 922IFuncs, like as aliases, don't create any new data or func. They are just a new 923symbol that dynamic linker resolves at runtime by calling a resolver function. 924 925IFuncs have a name and a resolver that is a function called by dynamic linker 926that returns address of another function associated with the name. 927 928IFunc may have an optional :ref:`linkage type <linkage>` and an optional 929:ref:`visibility style <visibility>`. 930 931Syntax:: 932 933 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver> 934 [, partition "name"] 935 936 937.. _langref_comdats: 938 939Comdats 940------- 941 942Comdat IR provides access to object file COMDAT/section group functionality 943which represents interrelated sections. 944 945Comdats have a name which represents the COMDAT key and a selection kind to 946provide input on how the linker deduplicates comdats with the same key in two 947different object files. A comdat must be included or omitted as a unit. 948Discarding the whole comdat is allowed but discarding a subset is not. 949 950A global object may be a member of at most one comdat. Aliases are placed in the 951same COMDAT that their aliasee computes to, if any. 952 953Syntax:: 954 955 $<Name> = comdat SelectionKind 956 957For selection kinds other than ``nodeduplicate``, only one of the duplicate 958comdats may be retained by the linker and the members of the remaining comdats 959must be discarded. The following selection kinds are supported: 960 961``any`` 962 The linker may choose any COMDAT key, the choice is arbitrary. 963``exactmatch`` 964 The linker may choose any COMDAT key but the sections must contain the 965 same data. 966``largest`` 967 The linker will choose the section containing the largest COMDAT key. 968``nodeduplicate`` 969 No deduplication is performed. 970``samesize`` 971 The linker may choose any COMDAT key but the sections must contain the 972 same amount of data. 973 974- XCOFF and Mach-O don't support COMDATs. 975- COFF supports all selection kinds. Non-``nodeduplicate`` selection kinds need 976 a non-local linkage COMDAT symbol. 977- ELF supports ``any`` and ``nodeduplicate``. 978- WebAssembly only supports ``any``. 979 980Here is an example of a COFF COMDAT where a function will only be selected if 981the COMDAT key's section is the largest: 982 983.. code-block:: text 984 985 $foo = comdat largest 986 @foo = global i32 2, comdat($foo) 987 988 define void @bar() comdat($foo) { 989 ret void 990 } 991 992In a COFF object file, this will create a COMDAT section with selection kind 993``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol 994and another COMDAT section with selection kind 995``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT 996section and contains the contents of the ``@bar`` symbol. 997 998As a syntactic sugar the ``$name`` can be omitted if the name is the same as 999the global name: 1000 1001.. code-block:: llvm 1002 1003 $foo = comdat any 1004 @foo = global i32 2, comdat 1005 @bar = global i32 3, comdat($foo) 1006 1007There are some restrictions on the properties of the global object. 1008It, or an alias to it, must have the same name as the COMDAT group when 1009targeting COFF. 1010The contents and size of this object may be used during link-time to determine 1011which COMDAT groups get selected depending on the selection kind. 1012Because the name of the object must match the name of the COMDAT group, the 1013linkage of the global object must not be local; local symbols can get renamed 1014if a collision occurs in the symbol table. 1015 1016The combined use of COMDATS and section attributes may yield surprising results. 1017For example: 1018 1019.. code-block:: llvm 1020 1021 $foo = comdat any 1022 $bar = comdat any 1023 @g1 = global i32 42, section "sec", comdat($foo) 1024 @g2 = global i32 42, section "sec", comdat($bar) 1025 1026From the object file perspective, this requires the creation of two sections 1027with the same name. This is necessary because both globals belong to different 1028COMDAT groups and COMDATs, at the object file level, are represented by 1029sections. 1030 1031Note that certain IR constructs like global variables and functions may 1032create COMDATs in the object file in addition to any which are specified using 1033COMDAT IR. This arises when the code generator is configured to emit globals 1034in individual sections (e.g. when `-data-sections` or `-function-sections` 1035is supplied to `llc`). 1036 1037.. _namedmetadatastructure: 1038 1039Named Metadata 1040-------------- 1041 1042Named metadata is a collection of metadata. :ref:`Metadata 1043nodes <metadata>` (but not metadata strings) are the only valid 1044operands for a named metadata. 1045 1046#. Named metadata are represented as a string of characters with the 1047 metadata prefix. The rules for metadata names are the same as for 1048 identifiers, but quoted names are not allowed. ``"\xx"`` type escapes 1049 are still valid, which allows any character to be part of a name. 1050 1051Syntax:: 1052 1053 ; Some unnamed metadata nodes, which are referenced by the named metadata. 1054 !0 = !{!"zero"} 1055 !1 = !{!"one"} 1056 !2 = !{!"two"} 1057 ; A named metadata. 1058 !name = !{!0, !1, !2} 1059 1060.. _paramattrs: 1061 1062Parameter Attributes 1063-------------------- 1064 1065The return type and each parameter of a function type may have a set of 1066*parameter attributes* associated with them. Parameter attributes are 1067used to communicate additional information about the result or 1068parameters of a function. Parameter attributes are considered to be part 1069of the function, not of the function type, so functions with different 1070parameter attributes can have the same function type. 1071 1072Parameter attributes are simple keywords that follow the type specified. 1073If multiple parameter attributes are needed, they are space separated. 1074For example: 1075 1076.. code-block:: llvm 1077 1078 declare i32 @printf(i8* noalias nocapture, ...) 1079 declare i32 @atoi(i8 zeroext) 1080 declare signext i8 @returns_signed_char() 1081 1082Note that any attributes for the function result (``nounwind``, 1083``readonly``) come immediately after the argument list. 1084 1085Currently, only the following parameter attributes are defined: 1086 1087``zeroext`` 1088 This indicates to the code generator that the parameter or return 1089 value should be zero-extended to the extent required by the target's 1090 ABI by the caller (for a parameter) or the callee (for a return value). 1091``signext`` 1092 This indicates to the code generator that the parameter or return 1093 value should be sign-extended to the extent required by the target's 1094 ABI (which is usually 32-bits) by the caller (for a parameter) or 1095 the callee (for a return value). 1096``inreg`` 1097 This indicates that this parameter or return value should be treated 1098 in a special target-dependent fashion while emitting code for 1099 a function call or return (usually, by putting it in a register as 1100 opposed to memory, though some targets use it to distinguish between 1101 two different kinds of registers). Use of this attribute is 1102 target-specific. 1103``byval(<ty>)`` 1104 This indicates that the pointer parameter should really be passed by 1105 value to the function. The attribute implies that a hidden copy of 1106 the pointee is made between the caller and the callee, so the callee 1107 is unable to modify the value in the caller. This attribute is only 1108 valid on LLVM pointer arguments. It is generally used to pass 1109 structs and arrays by value, but is also valid on pointers to 1110 scalars. The copy is considered to belong to the caller not the 1111 callee (for example, ``readonly`` functions should not write to 1112 ``byval`` parameters). This is not a valid attribute for return 1113 values. 1114 1115 The byval type argument indicates the in-memory value type, and 1116 must be the same as the pointee type of the argument. 1117 1118 The byval attribute also supports specifying an alignment with the 1119 align attribute. It indicates the alignment of the stack slot to 1120 form and the known alignment of the pointer specified to the call 1121 site. If the alignment is not specified, then the code generator 1122 makes a target-specific assumption. 1123 1124.. _attr_byref: 1125 1126``byref(<ty>)`` 1127 1128 The ``byref`` argument attribute allows specifying the pointee 1129 memory type of an argument. This is similar to ``byval``, but does 1130 not imply a copy is made anywhere, or that the argument is passed 1131 on the stack. This implies the pointer is dereferenceable up to 1132 the storage size of the type. 1133 1134 It is not generally permissible to introduce a write to an 1135 ``byref`` pointer. The pointer may have any address space and may 1136 be read only. 1137 1138 This is not a valid attribute for return values. 1139 1140 The alignment for an ``byref`` parameter can be explicitly 1141 specified by combining it with the ``align`` attribute, similar to 1142 ``byval``. If the alignment is not specified, then the code generator 1143 makes a target-specific assumption. 1144 1145 This is intended for representing ABI constraints, and is not 1146 intended to be inferred for optimization use. 1147 1148.. _attr_preallocated: 1149 1150``preallocated(<ty>)`` 1151 This indicates that the pointer parameter should really be passed by 1152 value to the function, and that the pointer parameter's pointee has 1153 already been initialized before the call instruction. This attribute 1154 is only valid on LLVM pointer arguments. The argument must be the value 1155 returned by the appropriate 1156 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` on non 1157 ``musttail`` calls, or the corresponding caller parameter in ``musttail`` 1158 calls, although it is ignored during codegen. 1159 1160 A non ``musttail`` function call with a ``preallocated`` attribute in 1161 any parameter must have a ``"preallocated"`` operand bundle. A ``musttail`` 1162 function call cannot have a ``"preallocated"`` operand bundle. 1163 1164 The preallocated attribute requires a type argument, which must be 1165 the same as the pointee type of the argument. 1166 1167 The preallocated attribute also supports specifying an alignment with the 1168 align attribute. It indicates the alignment of the stack slot to 1169 form and the known alignment of the pointer specified to the call 1170 site. If the alignment is not specified, then the code generator 1171 makes a target-specific assumption. 1172 1173.. _attr_inalloca: 1174 1175``inalloca(<ty>)`` 1176 1177 The ``inalloca`` argument attribute allows the caller to take the 1178 address of outgoing stack arguments. An ``inalloca`` argument must 1179 be a pointer to stack memory produced by an ``alloca`` instruction. 1180 The alloca, or argument allocation, must also be tagged with the 1181 inalloca keyword. Only the last argument may have the ``inalloca`` 1182 attribute, and that argument is guaranteed to be passed in memory. 1183 1184 An argument allocation may be used by a call at most once because 1185 the call may deallocate it. The ``inalloca`` attribute cannot be 1186 used in conjunction with other attributes that affect argument 1187 storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The 1188 ``inalloca`` attribute also disables LLVM's implicit lowering of 1189 large aggregate return values, which means that frontend authors 1190 must lower them with ``sret`` pointers. 1191 1192 When the call site is reached, the argument allocation must have 1193 been the most recent stack allocation that is still live, or the 1194 behavior is undefined. It is possible to allocate additional stack 1195 space after an argument allocation and before its call site, but it 1196 must be cleared off with :ref:`llvm.stackrestore 1197 <int_stackrestore>`. 1198 1199 The inalloca attribute requires a type argument, which must be the 1200 same as the pointee type of the argument. 1201 1202 See :doc:`InAlloca` for more information on how to use this 1203 attribute. 1204 1205``sret(<ty>)`` 1206 This indicates that the pointer parameter specifies the address of a 1207 structure that is the return value of the function in the source 1208 program. This pointer must be guaranteed by the caller to be valid: 1209 loads and stores to the structure may be assumed by the callee not 1210 to trap and to be properly aligned. This is not a valid attribute 1211 for return values. 1212 1213 The sret type argument specifies the in memory type, which must be 1214 the same as the pointee type of the argument. 1215 1216.. _attr_elementtype: 1217 1218``elementtype(<ty>)`` 1219 1220 The ``elementtype`` argument attribute can be used to specify a pointer 1221 element type in a way that is compatible with `opaque pointers 1222 <OpaquePointers.html>`__. 1223 1224 The ``elementtype`` attribute by itself does not carry any specific 1225 semantics. However, certain intrinsics may require this attribute to be 1226 present and assign it particular semantics. This will be documented on 1227 individual intrinsics. 1228 1229 The attribute may only be applied to pointer typed arguments of intrinsic 1230 calls. It cannot be applied to non-intrinsic calls, and cannot be applied 1231 to parameters on function declarations. For non-opaque pointers, the type 1232 passed to ``elementtype`` must match the pointer element type. 1233 1234.. _attr_align: 1235 1236``align <n>`` or ``align(<n>)`` 1237 This indicates that the pointer value or vector of pointers has the 1238 specified alignment. If applied to a vector of pointers, *all* pointers 1239 (elements) have the specified alignment. If the pointer value does not have 1240 the specified alignment, :ref:`poison value <poisonvalues>` is returned or 1241 passed instead. The ``align`` attribute should be combined with the 1242 ``noundef`` attribute to ensure a pointer is aligned, or otherwise the 1243 behavior is undefined. Note that ``align 1`` has no effect on non-byval, 1244 non-preallocated arguments. 1245 1246 Note that this attribute has additional semantics when combined with the 1247 ``byval`` or ``preallocated`` attribute, which are documented there. 1248 1249.. _noalias: 1250 1251``noalias`` 1252 This indicates that memory locations accessed via pointer values 1253 :ref:`based <pointeraliasing>` on the argument or return value are not also 1254 accessed, during the execution of the function, via pointer values not 1255 *based* on the argument or return value. This guarantee only holds for 1256 memory locations that are *modified*, by any means, during the execution of 1257 the function. The attribute on a return value also has additional semantics 1258 described below. The caller shares the responsibility with the callee for 1259 ensuring that these requirements are met. For further details, please see 1260 the discussion of the NoAlias response in :ref:`alias analysis <Must, May, 1261 or No>`. 1262 1263 Note that this definition of ``noalias`` is intentionally similar 1264 to the definition of ``restrict`` in C99 for function arguments. 1265 1266 For function return values, C99's ``restrict`` is not meaningful, 1267 while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias`` 1268 attribute on return values are stronger than the semantics of the attribute 1269 when used on function arguments. On function return values, the ``noalias`` 1270 attribute indicates that the function acts like a system memory allocation 1271 function, returning a pointer to allocated storage disjoint from the 1272 storage for any other object accessible to the caller. 1273 1274.. _nocapture: 1275 1276``nocapture`` 1277 This indicates that the callee does not :ref:`capture <pointercapture>` the 1278 pointer. This is not a valid attribute for return values. 1279 This attribute applies only to the particular copy of the pointer passed in 1280 this argument. A caller could pass two copies of the same pointer with one 1281 being annotated nocapture and the other not, and the callee could validly 1282 capture through the non annotated parameter. 1283 1284.. code-block:: llvm 1285 1286 define void @f(i8* nocapture %a, i8* %b) { 1287 ; (capture %b) 1288 } 1289 1290 call void @f(i8* @glb, i8* @glb) ; well-defined 1291 1292``nofree`` 1293 This indicates that callee does not free the pointer argument. This is not 1294 a valid attribute for return values. 1295 1296.. _nest: 1297 1298``nest`` 1299 This indicates that the pointer parameter can be excised using the 1300 :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid 1301 attribute for return values and can only be applied to one parameter. 1302 1303``returned`` 1304 This indicates that the function always returns the argument as its return 1305 value. This is a hint to the optimizer and code generator used when 1306 generating the caller, allowing value propagation, tail call optimization, 1307 and omission of register saves and restores in some cases; it is not 1308 checked or enforced when generating the callee. The parameter and the 1309 function return type must be valid operands for the 1310 :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for 1311 return values and can only be applied to one parameter. 1312 1313``nonnull`` 1314 This indicates that the parameter or return pointer is not null. This 1315 attribute may only be applied to pointer typed parameters. This is not 1316 checked or enforced by LLVM; if the parameter or return pointer is null, 1317 :ref:`poison value <poisonvalues>` is returned or passed instead. 1318 The ``nonnull`` attribute should be combined with the ``noundef`` attribute 1319 to ensure a pointer is not null or otherwise the behavior is undefined. 1320 1321``dereferenceable(<n>)`` 1322 This indicates that the parameter or return pointer is dereferenceable. This 1323 attribute may only be applied to pointer typed parameters. A pointer that 1324 is dereferenceable can be loaded from speculatively without a risk of 1325 trapping. The number of bytes known to be dereferenceable must be provided 1326 in parentheses. It is legal for the number of bytes to be less than the 1327 size of the pointee type. The ``nonnull`` attribute does not imply 1328 dereferenceability (consider a pointer to one element past the end of an 1329 array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in 1330 ``addrspace(0)`` (which is the default address space), except if the 1331 ``null_pointer_is_valid`` function attribute is present. 1332 ``n`` should be a positive number. The pointer should be well defined, 1333 otherwise it is undefined behavior. This means ``dereferenceable(<n>)`` 1334 implies ``noundef``. 1335 1336``dereferenceable_or_null(<n>)`` 1337 This indicates that the parameter or return value isn't both 1338 non-null and non-dereferenceable (up to ``<n>`` bytes) at the same 1339 time. All non-null pointers tagged with 1340 ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``. 1341 For address space 0 ``dereferenceable_or_null(<n>)`` implies that 1342 a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``, 1343 and in other address spaces ``dereferenceable_or_null(<n>)`` 1344 implies that a pointer is at least one of ``dereferenceable(<n>)`` 1345 or ``null`` (i.e. it may be both ``null`` and 1346 ``dereferenceable(<n>)``). This attribute may only be applied to 1347 pointer typed parameters. 1348 1349``swiftself`` 1350 This indicates that the parameter is the self/context parameter. This is not 1351 a valid attribute for return values and can only be applied to one 1352 parameter. 1353 1354``swiftasync`` 1355 This indicates that the parameter is the asynchronous context parameter and 1356 triggers the creation of a target-specific extended frame record to store 1357 this pointer. This is not a valid attribute for return values and can only 1358 be applied to one parameter. 1359 1360``swifterror`` 1361 This attribute is motivated to model and optimize Swift error handling. It 1362 can be applied to a parameter with pointer to pointer type or a 1363 pointer-sized alloca. At the call site, the actual argument that corresponds 1364 to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or 1365 the ``swifterror`` parameter of the caller. A ``swifterror`` value (either 1366 the parameter or the alloca) can only be loaded and stored from, or used as 1367 a ``swifterror`` argument. This is not a valid attribute for return values 1368 and can only be applied to one parameter. 1369 1370 These constraints allow the calling convention to optimize access to 1371 ``swifterror`` variables by associating them with a specific register at 1372 call boundaries rather than placing them in memory. Since this does change 1373 the calling convention, a function which uses the ``swifterror`` attribute 1374 on a parameter is not ABI-compatible with one which does not. 1375 1376 These constraints also allow LLVM to assume that a ``swifterror`` argument 1377 does not alias any other memory visible within a function and that a 1378 ``swifterror`` alloca passed as an argument does not escape. 1379 1380``immarg`` 1381 This indicates the parameter is required to be an immediate 1382 value. This must be a trivial immediate integer or floating-point 1383 constant. Undef or constant expressions are not valid. This is 1384 only valid on intrinsic declarations and cannot be applied to a 1385 call site or arbitrary function. 1386 1387``noundef`` 1388 This attribute applies to parameters and return values. If the value 1389 representation contains any undefined or poison bits, the behavior is 1390 undefined. Note that this does not refer to padding introduced by the 1391 type's storage representation. 1392 1393``alignstack(<n>)`` 1394 This indicates the alignment that should be considered by the backend when 1395 assigning this parameter to a stack slot during calling convention 1396 lowering. The enforcement of the specified alignment is target-dependent, 1397 as target-specific calling convention rules may override this value. This 1398 attribute serves the purpose of carrying language specific alignment 1399 information that is not mapped to base types in the backend (for example, 1400 over-alignment specification through language attributes). 1401 1402``allocalign`` 1403 The function parameter marked with this attribute is is the alignment in bytes of the 1404 newly allocated block returned by this function. The returned value must either have 1405 the specified alignment or be the null pointer. The return value MAY be more aligned 1406 than the requested alignment, but not less aligned. Invalid (e.g. non-power-of-2) 1407 alignments are permitted for the allocalign parameter, so long as the returned pointer 1408 is null. This attribute may only be applied to integer parameters. 1409 1410``allocptr`` 1411 The function parameter marked with this attribute is the pointer 1412 that will be manipulated by the allocator. For a realloc-like 1413 function the pointer will be invalidated upon success (but the 1414 same address may be returned), for a free-like function the 1415 pointer will always be invalidated. 1416 1417.. _gc: 1418 1419Garbage Collector Strategy Names 1420-------------------------------- 1421 1422Each function may specify a garbage collector strategy name, which is simply a 1423string: 1424 1425.. code-block:: llvm 1426 1427 define void @f() gc "name" { ... } 1428 1429The supported values of *name* includes those :ref:`built in to LLVM 1430<builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC 1431strategy will cause the compiler to alter its output in order to support the 1432named garbage collection algorithm. Note that LLVM itself does not contain a 1433garbage collector, this functionality is restricted to generating machine code 1434which can interoperate with a collector provided externally. 1435 1436.. _prefixdata: 1437 1438Prefix Data 1439----------- 1440 1441Prefix data is data associated with a function which the code 1442generator will emit immediately before the function's entrypoint. 1443The purpose of this feature is to allow frontends to associate 1444language-specific runtime metadata with specific functions and make it 1445available through the function pointer while still allowing the 1446function pointer to be called. 1447 1448To access the data for a given function, a program may bitcast the 1449function pointer to a pointer to the constant's type and dereference 1450index -1. This implies that the IR symbol points just past the end of 1451the prefix data. For instance, take the example of a function annotated 1452with a single ``i32``, 1453 1454.. code-block:: llvm 1455 1456 define void @f() prefix i32 123 { ... } 1457 1458The prefix data can be referenced as, 1459 1460.. code-block:: llvm 1461 1462 %0 = bitcast void* () @f to i32* 1463 %a = getelementptr inbounds i32, i32* %0, i32 -1 1464 %b = load i32, i32* %a 1465 1466Prefix data is laid out as if it were an initializer for a global variable 1467of the prefix data's type. The function will be placed such that the 1468beginning of the prefix data is aligned. This means that if the size 1469of the prefix data is not a multiple of the alignment size, the 1470function's entrypoint will not be aligned. If alignment of the 1471function's entrypoint is desired, padding must be added to the prefix 1472data. 1473 1474A function may have prefix data but no body. This has similar semantics 1475to the ``available_externally`` linkage in that the data may be used by the 1476optimizers but will not be emitted in the object file. 1477 1478.. _prologuedata: 1479 1480Prologue Data 1481------------- 1482 1483The ``prologue`` attribute allows arbitrary code (encoded as bytes) to 1484be inserted prior to the function body. This can be used for enabling 1485function hot-patching and instrumentation. 1486 1487To maintain the semantics of ordinary function calls, the prologue data must 1488have a particular format. Specifically, it must begin with a sequence of 1489bytes which decode to a sequence of machine instructions, valid for the 1490module's target, which transfer control to the point immediately succeeding 1491the prologue data, without performing any other visible action. This allows 1492the inliner and other passes to reason about the semantics of the function 1493definition without needing to reason about the prologue data. Obviously this 1494makes the format of the prologue data highly target dependent. 1495 1496A trivial example of valid prologue data for the x86 architecture is ``i8 144``, 1497which encodes the ``nop`` instruction: 1498 1499.. code-block:: text 1500 1501 define void @f() prologue i8 144 { ... } 1502 1503Generally prologue data can be formed by encoding a relative branch instruction 1504which skips the metadata, as in this example of valid prologue data for the 1505x86_64 architecture, where the first two bytes encode ``jmp .+10``: 1506 1507.. code-block:: text 1508 1509 %0 = type <{ i8, i8, i8* }> 1510 1511 define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... } 1512 1513A function may have prologue data but no body. This has similar semantics 1514to the ``available_externally`` linkage in that the data may be used by the 1515optimizers but will not be emitted in the object file. 1516 1517.. _personalityfn: 1518 1519Personality Function 1520-------------------- 1521 1522The ``personality`` attribute permits functions to specify what function 1523to use for exception handling. 1524 1525.. _attrgrp: 1526 1527Attribute Groups 1528---------------- 1529 1530Attribute groups are groups of attributes that are referenced by objects within 1531the IR. They are important for keeping ``.ll`` files readable, because a lot of 1532functions will use the same set of attributes. In the degenerative case of a 1533``.ll`` file that corresponds to a single ``.c`` file, the single attribute 1534group will capture the important command line flags used to build that file. 1535 1536An attribute group is a module-level object. To use an attribute group, an 1537object references the attribute group's ID (e.g. ``#37``). An object may refer 1538to more than one attribute group. In that situation, the attributes from the 1539different groups are merged. 1540 1541Here is an example of attribute groups for a function that should always be 1542inlined, has a stack alignment of 4, and which shouldn't use SSE instructions: 1543 1544.. code-block:: llvm 1545 1546 ; Target-independent attributes: 1547 attributes #0 = { alwaysinline alignstack=4 } 1548 1549 ; Target-dependent attributes: 1550 attributes #1 = { "no-sse" } 1551 1552 ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse". 1553 define void @f() #0 #1 { ... } 1554 1555.. _fnattrs: 1556 1557Function Attributes 1558------------------- 1559 1560Function attributes are set to communicate additional information about 1561a function. Function attributes are considered to be part of the 1562function, not of the function type, so functions with different function 1563attributes can have the same function type. 1564 1565Function attributes are simple keywords that follow the type specified. 1566If multiple attributes are needed, they are space separated. For 1567example: 1568 1569.. code-block:: llvm 1570 1571 define void @f() noinline { ... } 1572 define void @f() alwaysinline { ... } 1573 define void @f() alwaysinline optsize { ... } 1574 define void @f() optsize { ... } 1575 1576``alignstack(<n>)`` 1577 This attribute indicates that, when emitting the prologue and 1578 epilogue, the backend should forcibly align the stack pointer. 1579 Specify the desired alignment, which must be a power of two, in 1580 parentheses. 1581``"alloc-family"="FAMILY"`` 1582 This indicates which "family" an allocator function is part of. To avoid 1583 collisions, the family name should match the mangled name of the primary 1584 allocator function, that is "malloc" for malloc/calloc/realloc/free, 1585 "_Znwm" for ``::operator::new`` and ``::operator::delete``, and 1586 "_ZnwmSt11align_val_t" for aligned ``::operator::new`` and 1587 ``::operator::delete``. Matching malloc/realloc/free calls within a family 1588 can be optimized, but mismatched ones will be left alone. 1589``allockind("KIND")`` 1590 Describes the behavior of an allocation function. The KIND string contains comma 1591 separated entries from the following options: 1592 1593 * "alloc": the function returns a new block of memory or null. 1594 * "realloc": the function returns a new block of memory or null. If the 1595 result is non-null the memory contents from the start of the block up to 1596 the smaller of the original allocation size and the new allocation size 1597 will match that of the ``allocptr`` argument and the ``allocptr`` 1598 argument is invalidated, even if the function returns the same address. 1599 * "free": the function frees the block of memory specified by ``allocptr``. 1600 * "uninitialized": Any newly-allocated memory (either a new block from 1601 a "alloc" function or the enlarged capacity from a "realloc" function) 1602 will be uninitialized. 1603 * "zeroed": Any newly-allocated memory (either a new block from a "alloc" 1604 function or the enlarged capacity from a "realloc" function) will be 1605 zeroed. 1606 * "aligned": the function returns memory aligned according to the 1607 ``allocalign`` parameter. 1608 1609 The first three options are mutually exclusive, and the remaining options 1610 describe more details of how the function behaves. The remaining options 1611 are invalid for "free"-type functions. 1612``allocsize(<EltSizeParam>[, <NumEltsParam>])`` 1613 This attribute indicates that the annotated function will always return at 1614 least a given number of bytes (or null). Its arguments are zero-indexed 1615 parameter numbers; if one argument is provided, then it's assumed that at 1616 least ``CallSite.Args[EltSizeParam]`` bytes will be available at the 1617 returned pointer. If two are provided, then it's assumed that 1618 ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are 1619 available. The referenced parameters must be integer types. No assumptions 1620 are made about the contents of the returned block of memory. 1621``alwaysinline`` 1622 This attribute indicates that the inliner should attempt to inline 1623 this function into callers whenever possible, ignoring any active 1624 inlining size threshold for this caller. 1625``builtin`` 1626 This indicates that the callee function at a call site should be 1627 recognized as a built-in function, even though the function's declaration 1628 uses the ``nobuiltin`` attribute. This is only valid at call sites for 1629 direct calls to functions that are declared with the ``nobuiltin`` 1630 attribute. 1631``cold`` 1632 This attribute indicates that this function is rarely called. When 1633 computing edge weights, basic blocks post-dominated by a cold 1634 function call are also considered to be cold; and, thus, given low 1635 weight. 1636``convergent`` 1637 In some parallel execution models, there exist operations that cannot be 1638 made control-dependent on any additional values. We call such operations 1639 ``convergent``, and mark them with this attribute. 1640 1641 The ``convergent`` attribute may appear on functions or call/invoke 1642 instructions. When it appears on a function, it indicates that calls to 1643 this function should not be made control-dependent on additional values. 1644 For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so 1645 calls to this intrinsic cannot be made control-dependent on additional 1646 values. 1647 1648 When it appears on a call/invoke, the ``convergent`` attribute indicates 1649 that we should treat the call as though we're calling a convergent 1650 function. This is particularly useful on indirect calls; without this we 1651 may treat such calls as though the target is non-convergent. 1652 1653 The optimizer may remove the ``convergent`` attribute on functions when it 1654 can prove that the function does not execute any convergent operations. 1655 Similarly, the optimizer may remove ``convergent`` on calls/invokes when it 1656 can prove that the call/invoke cannot call a convergent function. 1657``disable_sanitizer_instrumentation`` 1658 When instrumenting code with sanitizers, it can be important to skip certain 1659 functions to ensure no instrumentation is applied to them. 1660 1661 This attribute is not always similar to absent ``sanitize_<name>`` 1662 attributes: depending on the specific sanitizer, code can be inserted into 1663 functions regardless of the ``sanitize_<name>`` attribute to prevent false 1664 positive reports. 1665 1666 ``disable_sanitizer_instrumentation`` disables all kinds of instrumentation, 1667 taking precedence over the ``sanitize_<name>`` attributes and other compiler 1668 flags. 1669``"dontcall-error"`` 1670 This attribute denotes that an error diagnostic should be emitted when a 1671 call of a function with this attribute is not eliminated via optimization. 1672 Front ends can provide optional ``srcloc`` metadata nodes on call sites of 1673 such callees to attach information about where in the source language such a 1674 call came from. A string value can be provided as a note. 1675``"dontcall-warn"`` 1676 This attribute denotes that a warning diagnostic should be emitted when a 1677 call of a function with this attribute is not eliminated via optimization. 1678 Front ends can provide optional ``srcloc`` metadata nodes on call sites of 1679 such callees to attach information about where in the source language such a 1680 call came from. A string value can be provided as a note. 1681``fn_ret_thunk_extern`` 1682 This attribute tells the code generator that returns from functions should 1683 be replaced with jumps to externally-defined architecture-specific symbols. 1684 For X86, this symbol's identifier is ``__x86_return_thunk``. 1685``"frame-pointer"`` 1686 This attribute tells the code generator whether the function 1687 should keep the frame pointer. The code generator may emit the frame pointer 1688 even if this attribute says the frame pointer can be eliminated. 1689 The allowed string values are: 1690 1691 * ``"none"`` (default) - the frame pointer can be eliminated. 1692 * ``"non-leaf"`` - the frame pointer should be kept if the function calls 1693 other functions. 1694 * ``"all"`` - the frame pointer should be kept. 1695``hot`` 1696 This attribute indicates that this function is a hot spot of the program 1697 execution. The function will be optimized more aggressively and will be 1698 placed into special subsection of the text section to improving locality. 1699 1700 When profile feedback is enabled, this attribute has the precedence over 1701 the profile information. By marking a function ``hot``, users can work 1702 around the cases where the training input does not have good coverage 1703 on all the hot functions. 1704``inaccessiblememonly`` 1705 This attribute indicates that the function may only access memory that 1706 is not accessible by the module being compiled before return from the 1707 function. This is a weaker form of ``readnone``. If the function reads 1708 or writes other memory, the behavior is undefined. 1709 1710 For clarity, note that such functions are allowed to return new memory 1711 which is ``noalias`` with respect to memory already accessible from 1712 the module. That is, a function can be both ``inaccessiblememonly`` and 1713 have a ``noalias`` return which introduces a new, potentially initialized, 1714 allocation. 1715``inaccessiblemem_or_argmemonly`` 1716 This attribute indicates that the function may only access memory that is 1717 either not accessible by the module being compiled, or is pointed to 1718 by its pointer arguments. This is a weaker form of ``argmemonly``. If the 1719 function reads or writes other memory, the behavior is undefined. 1720``inlinehint`` 1721 This attribute indicates that the source code contained a hint that 1722 inlining this function is desirable (such as the "inline" keyword in 1723 C/C++). It is just a hint; it imposes no requirements on the 1724 inliner. 1725``jumptable`` 1726 This attribute indicates that the function should be added to a 1727 jump-instruction table at code-generation time, and that all address-taken 1728 references to this function should be replaced with a reference to the 1729 appropriate jump-instruction-table function pointer. Note that this creates 1730 a new pointer for the original function, which means that code that depends 1731 on function-pointer identity can break. So, any function annotated with 1732 ``jumptable`` must also be ``unnamed_addr``. 1733``minsize`` 1734 This attribute suggests that optimization passes and code generator 1735 passes make choices that keep the code size of this function as small 1736 as possible and perform optimizations that may sacrifice runtime 1737 performance in order to minimize the size of the generated code. 1738``naked`` 1739 This attribute disables prologue / epilogue emission for the 1740 function. This can have very system-specific consequences. 1741``"no-inline-line-tables"`` 1742 When this attribute is set to true, the inliner discards source locations 1743 when inlining code and instead uses the source location of the call site. 1744 Breakpoints set on code that was inlined into the current function will 1745 not fire during the execution of the inlined call sites. If the debugger 1746 stops inside an inlined call site, it will appear to be stopped at the 1747 outermost inlined call site. 1748``no-jump-tables`` 1749 When this attribute is set to true, the jump tables and lookup tables that 1750 can be generated from a switch case lowering are disabled. 1751``nobuiltin`` 1752 This indicates that the callee function at a call site is not recognized as 1753 a built-in function. LLVM will retain the original call and not replace it 1754 with equivalent code based on the semantics of the built-in function, unless 1755 the call site uses the ``builtin`` attribute. This is valid at call sites 1756 and on function declarations and definitions. 1757``noduplicate`` 1758 This attribute indicates that calls to the function cannot be 1759 duplicated. A call to a ``noduplicate`` function may be moved 1760 within its parent function, but may not be duplicated within 1761 its parent function. 1762 1763 A function containing a ``noduplicate`` call may still 1764 be an inlining candidate, provided that the call is not 1765 duplicated by inlining. That implies that the function has 1766 internal linkage and only has one call site, so the original 1767 call is dead after inlining. 1768``nofree`` 1769 This function attribute indicates that the function does not, directly or 1770 transitively, call a memory-deallocation function (``free``, for example) 1771 on a memory allocation which existed before the call. 1772 1773 As a result, uncaptured pointers that are known to be dereferenceable 1774 prior to a call to a function with the ``nofree`` attribute are still 1775 known to be dereferenceable after the call. The capturing condition is 1776 necessary in environments where the function might communicate the 1777 pointer to another thread which then deallocates the memory. Alternatively, 1778 ``nosync`` would ensure such communication cannot happen and even captured 1779 pointers cannot be freed by the function. 1780 1781 A ``nofree`` function is explicitly allowed to free memory which it 1782 allocated or (if not ``nosync``) arrange for another thread to free 1783 memory on it's behalf. As a result, perhaps surprisingly, a ``nofree`` 1784 function can return a pointer to a previously deallocated memory object. 1785``noimplicitfloat`` 1786 Disallows implicit floating-point code. This inhibits optimizations that 1787 use floating-point code and floating-point/SIMD/vector registers for 1788 operations that are not nominally floating-point. LLVM instructions that 1789 perform floating-point operations or require access to floating-point 1790 registers may still cause floating-point code to be generated. 1791``noinline`` 1792 This attribute indicates that the inliner should never inline this 1793 function in any situation. This attribute may not be used together 1794 with the ``alwaysinline`` attribute. 1795``nomerge`` 1796 This attribute indicates that calls to this function should never be merged 1797 during optimization. For example, it will prevent tail merging otherwise 1798 identical code sequences that raise an exception or terminate the program. 1799 Tail merging normally reduces the precision of source location information, 1800 making stack traces less useful for debugging. This attribute gives the 1801 user control over the tradeoff between code size and debug information 1802 precision. 1803``nonlazybind`` 1804 This attribute suppresses lazy symbol binding for the function. This 1805 may make calls to the function faster, at the cost of extra program 1806 startup time if the function is not called during program startup. 1807``noprofile`` 1808 This function attribute prevents instrumentation based profiling, used for 1809 coverage or profile based optimization, from being added to a function, 1810 even when inlined. 1811``noredzone`` 1812 This attribute indicates that the code generator should not use a 1813 red zone, even if the target-specific ABI normally permits it. 1814``indirect-tls-seg-refs`` 1815 This attribute indicates that the code generator should not use 1816 direct TLS access through segment registers, even if the 1817 target-specific ABI normally permits it. 1818``noreturn`` 1819 This function attribute indicates that the function never returns 1820 normally, hence through a return instruction. This produces undefined 1821 behavior at runtime if the function ever does dynamically return. Annotated 1822 functions may still raise an exception, i.a., ``nounwind`` is not implied. 1823``norecurse`` 1824 This function attribute indicates that the function does not call itself 1825 either directly or indirectly down any possible call path. This produces 1826 undefined behavior at runtime if the function ever does recurse. 1827 1828.. _langref_willreturn: 1829 1830``willreturn`` 1831 This function attribute indicates that a call of this function will 1832 either exhibit undefined behavior or comes back and continues execution 1833 at a point in the existing call stack that includes the current invocation. 1834 Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied. 1835 If an invocation of an annotated function does not return control back 1836 to a point in the call stack, the behavior is undefined. 1837``nosync`` 1838 This function attribute indicates that the function does not communicate 1839 (synchronize) with another thread through memory or other well-defined means. 1840 Synchronization is considered possible in the presence of `atomic` accesses 1841 that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses, 1842 as well as `convergent` function calls. Note that through `convergent` function calls 1843 non-memory communication, e.g., cross-lane operations, are possible and are also 1844 considered synchronization. However `convergent` does not contradict `nosync`. 1845 If an annotated function does ever synchronize with another thread, 1846 the behavior is undefined. 1847``nounwind`` 1848 This function attribute indicates that the function never raises an 1849 exception. If the function does raise an exception, its runtime 1850 behavior is undefined. However, functions marked nounwind may still 1851 trap or generate asynchronous exceptions. Exception handling schemes 1852 that are recognized by LLVM to handle asynchronous exceptions, such 1853 as SEH, will still provide their implementation defined semantics. 1854``nosanitize_bounds`` 1855 This attribute indicates that bounds checking sanitizer instrumentation 1856 is disabled for this function. 1857``nosanitize_coverage`` 1858 This attribute indicates that SanitizerCoverage instrumentation is disabled 1859 for this function. 1860``null_pointer_is_valid`` 1861 If ``null_pointer_is_valid`` is set, then the ``null`` address 1862 in address-space 0 is considered to be a valid address for memory loads and 1863 stores. Any analysis or optimization should not treat dereferencing a 1864 pointer to ``null`` as undefined behavior in this function. 1865 Note: Comparing address of a global variable to ``null`` may still 1866 evaluate to false because of a limitation in querying this attribute inside 1867 constant expressions. 1868``optforfuzzing`` 1869 This attribute indicates that this function should be optimized 1870 for maximum fuzzing signal. 1871``optnone`` 1872 This function attribute indicates that most optimization passes will skip 1873 this function, with the exception of interprocedural optimization passes. 1874 Code generation defaults to the "fast" instruction selector. 1875 This attribute cannot be used together with the ``alwaysinline`` 1876 attribute; this attribute is also incompatible 1877 with the ``minsize`` attribute and the ``optsize`` attribute. 1878 1879 This attribute requires the ``noinline`` attribute to be specified on 1880 the function as well, so the function is never inlined into any caller. 1881 Only functions with the ``alwaysinline`` attribute are valid 1882 candidates for inlining into the body of this function. 1883``optsize`` 1884 This attribute suggests that optimization passes and code generator 1885 passes make choices that keep the code size of this function low, 1886 and otherwise do optimizations specifically to reduce code size as 1887 long as they do not significantly impact runtime performance. 1888``"patchable-function"`` 1889 This attribute tells the code generator that the code 1890 generated for this function needs to follow certain conventions that 1891 make it possible for a runtime function to patch over it later. 1892 The exact effect of this attribute depends on its string value, 1893 for which there currently is one legal possibility: 1894 1895 * ``"prologue-short-redirect"`` - This style of patchable 1896 function is intended to support patching a function prologue to 1897 redirect control away from the function in a thread safe 1898 manner. It guarantees that the first instruction of the 1899 function will be large enough to accommodate a short jump 1900 instruction, and will be sufficiently aligned to allow being 1901 fully changed via an atomic compare-and-swap instruction. 1902 While the first requirement can be satisfied by inserting large 1903 enough NOP, LLVM can and will try to re-purpose an existing 1904 instruction (i.e. one that would have to be emitted anyway) as 1905 the patchable instruction larger than a short jump. 1906 1907 ``"prologue-short-redirect"`` is currently only supported on 1908 x86-64. 1909 1910 This attribute by itself does not imply restrictions on 1911 inter-procedural optimizations. All of the semantic effects the 1912 patching may have to be separately conveyed via the linkage type. 1913``"probe-stack"`` 1914 This attribute indicates that the function will trigger a guard region 1915 in the end of the stack. It ensures that accesses to the stack must be 1916 no further apart than the size of the guard region to a previous 1917 access of the stack. It takes one required string value, the name of 1918 the stack probing function that will be called. 1919 1920 If a function that has a ``"probe-stack"`` attribute is inlined into 1921 a function with another ``"probe-stack"`` attribute, the resulting 1922 function has the ``"probe-stack"`` attribute of the caller. If a 1923 function that has a ``"probe-stack"`` attribute is inlined into a 1924 function that has no ``"probe-stack"`` attribute at all, the resulting 1925 function has the ``"probe-stack"`` attribute of the callee. 1926``readnone`` 1927 On a function, this attribute indicates that the function computes its 1928 result (or decides to unwind an exception) based strictly on its arguments, 1929 without dereferencing any pointer arguments or otherwise accessing 1930 any mutable state (e.g. memory, control registers, etc) visible outside the 1931 ``readnone`` function. It does not write through any pointer arguments 1932 (including ``byval`` arguments) and never changes any state visible to 1933 callers. This means while it cannot unwind exceptions by calling the ``C++`` 1934 exception throwing methods (since they write to memory), there may be 1935 non-``C++`` mechanisms that throw exceptions without writing to LLVM visible 1936 memory. 1937 1938 On an argument, this attribute indicates that the function does not 1939 dereference that pointer argument, even though it may read or write the 1940 memory that the pointer points to if accessed through other pointers. 1941 1942 If a readnone function reads or writes memory visible outside the function, 1943 or has other side-effects, the behavior is undefined. If a 1944 function reads from or writes to a readnone pointer argument, the behavior 1945 is undefined. 1946``readonly`` 1947 On a function, this attribute indicates that the function does not write 1948 through any pointer arguments (including ``byval`` arguments) or otherwise 1949 modify any state (e.g. memory, control registers, etc) visible outside the 1950 ``readonly`` function. It may dereference pointer arguments and read 1951 state that may be set in the caller. A readonly function always 1952 returns the same value (or unwinds an exception identically) when 1953 called with the same set of arguments and global state. This means while it 1954 cannot unwind exceptions by calling the ``C++`` exception throwing methods 1955 (since they write to memory), there may be non-``C++`` mechanisms that throw 1956 exceptions without writing to LLVM visible memory. 1957 1958 On an argument, this attribute indicates that the function does not write 1959 through this pointer argument, even though it may write to the memory that 1960 the pointer points to. 1961 1962 If a readonly function writes memory visible outside the function, or has 1963 other side-effects, the behavior is undefined. If a function writes to a 1964 readonly pointer argument, the behavior is undefined. 1965``"stack-probe-size"`` 1966 This attribute controls the behavior of stack probes: either 1967 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any. 1968 It defines the size of the guard region. It ensures that if the function 1969 may use more stack space than the size of the guard region, stack probing 1970 sequence will be emitted. It takes one required integer value, which 1971 is 4096 by default. 1972 1973 If a function that has a ``"stack-probe-size"`` attribute is inlined into 1974 a function with another ``"stack-probe-size"`` attribute, the resulting 1975 function has the ``"stack-probe-size"`` attribute that has the lower 1976 numeric value. If a function that has a ``"stack-probe-size"`` attribute is 1977 inlined into a function that has no ``"stack-probe-size"`` attribute 1978 at all, the resulting function has the ``"stack-probe-size"`` attribute 1979 of the callee. 1980``"no-stack-arg-probe"`` 1981 This attribute disables ABI-required stack probes, if any. 1982``writeonly`` 1983 On a function, this attribute indicates that the function may write to but 1984 does not read from memory visible outside the ``writeonly`` function. 1985 1986 On an argument, this attribute indicates that the function may write to but 1987 does not read through this pointer argument (even though it may read from 1988 the memory that the pointer points to). 1989 1990 If a writeonly function reads memory visible outside the function or has 1991 other side-effects, the behavior is undefined. If a function reads 1992 from a writeonly pointer argument, the behavior is undefined. 1993``argmemonly`` 1994 This attribute indicates that the only memory accesses inside function are 1995 loads and stores from objects pointed to by its pointer-typed arguments, 1996 with arbitrary offsets. Or in other words, all memory operations in the 1997 function can refer to memory only using pointers based on its function 1998 arguments. 1999 2000 Note that ``argmemonly`` can be used together with ``readonly`` attribute 2001 in order to specify that function reads only from its arguments. 2002 2003 If an argmemonly function reads or writes memory other than the pointer 2004 arguments, or has other side-effects, the behavior is undefined. 2005``returns_twice`` 2006 This attribute indicates that this function can return twice. The C 2007 ``setjmp`` is an example of such a function. The compiler disables 2008 some optimizations (like tail calls) in the caller of these 2009 functions. 2010``safestack`` 2011 This attribute indicates that 2012 `SafeStack <https://clang.llvm.org/docs/SafeStack.html>`_ 2013 protection is enabled for this function. 2014 2015 If a function that has a ``safestack`` attribute is inlined into a 2016 function that doesn't have a ``safestack`` attribute or which has an 2017 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting 2018 function will have a ``safestack`` attribute. 2019``sanitize_address`` 2020 This attribute indicates that AddressSanitizer checks 2021 (dynamic address safety analysis) are enabled for this function. 2022``sanitize_memory`` 2023 This attribute indicates that MemorySanitizer checks (dynamic detection 2024 of accesses to uninitialized memory) are enabled for this function. 2025``sanitize_thread`` 2026 This attribute indicates that ThreadSanitizer checks 2027 (dynamic thread safety analysis) are enabled for this function. 2028``sanitize_hwaddress`` 2029 This attribute indicates that HWAddressSanitizer checks 2030 (dynamic address safety analysis based on tagged pointers) are enabled for 2031 this function. 2032``sanitize_memtag`` 2033 This attribute indicates that MemTagSanitizer checks 2034 (dynamic address safety analysis based on Armv8 MTE) are enabled for 2035 this function. 2036``speculative_load_hardening`` 2037 This attribute indicates that 2038 `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_ 2039 should be enabled for the function body. 2040 2041 Speculative Load Hardening is a best-effort mitigation against 2042 information leak attacks that make use of control flow 2043 miss-speculation - specifically miss-speculation of whether a branch 2044 is taken or not. Typically vulnerabilities enabling such attacks are 2045 classified as "Spectre variant #1". Notably, this does not attempt to 2046 mitigate against miss-speculation of branch target, classified as 2047 "Spectre variant #2" vulnerabilities. 2048 2049 When inlining, the attribute is sticky. Inlining a function that carries 2050 this attribute will cause the caller to gain the attribute. This is intended 2051 to provide a maximally conservative model where the code in a function 2052 annotated with this attribute will always (even after inlining) end up 2053 hardened. 2054``speculatable`` 2055 This function attribute indicates that the function does not have any 2056 effects besides calculating its result and does not have undefined behavior. 2057 Note that ``speculatable`` is not enough to conclude that along any 2058 particular execution path the number of calls to this function will not be 2059 externally observable. This attribute is only valid on functions 2060 and declarations, not on individual call sites. If a function is 2061 incorrectly marked as speculatable and really does exhibit 2062 undefined behavior, the undefined behavior may be observed even 2063 if the call site is dead code. 2064 2065``ssp`` 2066 This attribute indicates that the function should emit a stack 2067 smashing protector. It is in the form of a "canary" --- a random value 2068 placed on the stack before the local variables that's checked upon 2069 return from the function to see if it has been overwritten. A 2070 heuristic is used to determine if a function needs stack protectors 2071 or not. The heuristic used will enable protectors for functions with: 2072 2073 - Character arrays larger than ``ssp-buffer-size`` (default 8). 2074 - Aggregates containing character arrays larger than ``ssp-buffer-size``. 2075 - Calls to alloca() with variable sizes or constant sizes greater than 2076 ``ssp-buffer-size``. 2077 2078 Variables that are identified as requiring a protector will be arranged 2079 on the stack such that they are adjacent to the stack protector guard. 2080 2081 If a function with an ``ssp`` attribute is inlined into a calling function, 2082 the attribute is not carried over to the calling function. 2083 2084``sspstrong`` 2085 This attribute indicates that the function should emit a stack smashing 2086 protector. This attribute causes a strong heuristic to be used when 2087 determining if a function needs stack protectors. The strong heuristic 2088 will enable protectors for functions with: 2089 2090 - Arrays of any size and type 2091 - Aggregates containing an array of any size and type. 2092 - Calls to alloca(). 2093 - Local variables that have had their address taken. 2094 2095 Variables that are identified as requiring a protector will be arranged 2096 on the stack such that they are adjacent to the stack protector guard. 2097 The specific layout rules are: 2098 2099 #. Large arrays and structures containing large arrays 2100 (``>= ssp-buffer-size``) are closest to the stack protector. 2101 #. Small arrays and structures containing small arrays 2102 (``< ssp-buffer-size``) are 2nd closest to the protector. 2103 #. Variables that have had their address taken are 3rd closest to the 2104 protector. 2105 2106 This overrides the ``ssp`` function attribute. 2107 2108 If a function with an ``sspstrong`` attribute is inlined into a calling 2109 function which has an ``ssp`` attribute, the calling function's attribute 2110 will be upgraded to ``sspstrong``. 2111 2112``sspreq`` 2113 This attribute indicates that the function should *always* emit a stack 2114 smashing protector. This overrides the ``ssp`` and ``sspstrong`` function 2115 attributes. 2116 2117 Variables that are identified as requiring a protector will be arranged 2118 on the stack such that they are adjacent to the stack protector guard. 2119 The specific layout rules are: 2120 2121 #. Large arrays and structures containing large arrays 2122 (``>= ssp-buffer-size``) are closest to the stack protector. 2123 #. Small arrays and structures containing small arrays 2124 (``< ssp-buffer-size``) are 2nd closest to the protector. 2125 #. Variables that have had their address taken are 3rd closest to the 2126 protector. 2127 2128 If a function with an ``sspreq`` attribute is inlined into a calling 2129 function which has an ``ssp`` or ``sspstrong`` attribute, the calling 2130 function's attribute will be upgraded to ``sspreq``. 2131 2132``strictfp`` 2133 This attribute indicates that the function was called from a scope that 2134 requires strict floating-point semantics. LLVM will not attempt any 2135 optimizations that require assumptions about the floating-point rounding 2136 mode or that might alter the state of floating-point status flags that 2137 might otherwise be set or cleared by calling this function. LLVM will 2138 not introduce any new floating-point instructions that may trap. 2139 2140``"denormal-fp-math"`` 2141 This indicates the denormal (subnormal) handling that may be 2142 assumed for the default floating-point environment. This is a 2143 comma separated pair. The elements may be one of ``"ieee"``, 2144 ``"preserve-sign"``, or ``"positive-zero"``. The first entry 2145 indicates the flushing mode for the result of floating point 2146 operations. The second indicates the handling of denormal inputs 2147 to floating point instructions. For compatibility with older 2148 bitcode, if the second value is omitted, both input and output 2149 modes will assume the same mode. 2150 2151 If this is attribute is not specified, the default is 2152 ``"ieee,ieee"``. 2153 2154 If the output mode is ``"preserve-sign"``, or ``"positive-zero"``, 2155 denormal outputs may be flushed to zero by standard floating-point 2156 operations. It is not mandated that flushing to zero occurs, but if 2157 a denormal output is flushed to zero, it must respect the sign 2158 mode. Not all targets support all modes. While this indicates the 2159 expected floating point mode the function will be executed with, 2160 this does not make any attempt to ensure the mode is 2161 consistent. User or platform code is expected to set the floating 2162 point mode appropriately before function entry. 2163 2164 If the input mode is ``"preserve-sign"``, or ``"positive-zero"``, a 2165 floating-point operation must treat any input denormal value as 2166 zero. In some situations, if an instruction does not respect this 2167 mode, the input may need to be converted to 0 as if by 2168 ``@llvm.canonicalize`` during lowering for correctness. 2169 2170``"denormal-fp-math-f32"`` 2171 Same as ``"denormal-fp-math"``, but only controls the behavior of 2172 the 32-bit float type (or vectors of 32-bit floats). If both are 2173 are present, this overrides ``"denormal-fp-math"``. Not all targets 2174 support separately setting the denormal mode per type, and no 2175 attempt is made to diagnose unsupported uses. Currently this 2176 attribute is respected by the AMDGPU and NVPTX backends. 2177 2178``"thunk"`` 2179 This attribute indicates that the function will delegate to some other 2180 function with a tail call. The prototype of a thunk should not be used for 2181 optimization purposes. The caller is expected to cast the thunk prototype to 2182 match the thunk target prototype. 2183 2184``"tls-load-hoist"`` 2185 This attribute indicates that the function will try to reduce redundant 2186 tls address calculation by hoisting tls variable. 2187 2188``uwtable[(sync|async)]`` 2189 This attribute indicates that the ABI being targeted requires that 2190 an unwind table entry be produced for this function even if we can 2191 show that no exceptions passes by it. This is normally the case for 2192 the ELF x86-64 abi, but it can be disabled for some compilation 2193 units. The optional parameter describes what kind of unwind tables 2194 to generate: ``sync`` for normal unwind tables, ``async`` for asynchronous 2195 (instruction precise) unwind tables. Without the parameter, the attribute 2196 ``uwtable`` is equivalent to ``uwtable(async)``. 2197``nocf_check`` 2198 This attribute indicates that no control-flow check will be performed on 2199 the attributed entity. It disables -fcf-protection=<> for a specific 2200 entity to fine grain the HW control flow protection mechanism. The flag 2201 is target independent and currently appertains to a function or function 2202 pointer. 2203``shadowcallstack`` 2204 This attribute indicates that the ShadowCallStack checks are enabled for 2205 the function. The instrumentation checks that the return address for the 2206 function has not changed between the function prolog and epilog. It is 2207 currently x86_64-specific. 2208 2209.. _langref_mustprogress: 2210 2211``mustprogress`` 2212 This attribute indicates that the function is required to return, unwind, 2213 or interact with the environment in an observable way e.g. via a volatile 2214 memory access, I/O, or other synchronization. The ``mustprogress`` 2215 attribute is intended to model the requirements of the first section of 2216 [intro.progress] of the C++ Standard. As a consequence, a loop in a 2217 function with the `mustprogress` attribute can be assumed to terminate if 2218 it does not interact with the environment in an observable way, and 2219 terminating loops without side-effects can be removed. If a `mustprogress` 2220 function does not satisfy this contract, the behavior is undefined. This 2221 attribute does not apply transitively to callees, but does apply to call 2222 sites within the function. Note that `willreturn` implies `mustprogress`. 2223``"warn-stack-size"="<threshold>"`` 2224 This attribute sets a threshold to emit diagnostics once the frame size is 2225 known should the frame size exceed the specified value. It takes one 2226 required integer value, which should be a non-negative integer, and less 2227 than `UINT_MAX`. It's unspecified which threshold will be used when 2228 duplicate definitions are linked together with differing values. 2229``vscale_range(<min>[, <max>])`` 2230 This attribute indicates the minimum and maximum vscale value for the given 2231 function. The min must be greater than 0. A maximum value of 0 means 2232 unbounded. If the optional max value is omitted then max is set to the 2233 value of min. If the attribute is not present, no assumptions are made 2234 about the range of vscale. 2235``"min-legal-vector-width"="<size>"`` 2236 This attribute indicates the minimum legal vector width required by the 2237 calling conversion. It is the maximum width of vector arguments and 2238 returnings in the function and functions called by this function. Because 2239 all the vectors are supposed to be legal type for compatibility. 2240 Backends are free to ignore the attribute if they don't need to support 2241 different maximum legal vector types or such information can be inferred by 2242 other attributes. 2243 2244Call Site Attributes 2245---------------------- 2246 2247In addition to function attributes the following call site only 2248attributes are supported: 2249 2250``vector-function-abi-variant`` 2251 This attribute can be attached to a :ref:`call <i_call>` to list 2252 the vector functions associated to the function. Notice that the 2253 attribute cannot be attached to a :ref:`invoke <i_invoke>` or a 2254 :ref:`callbr <i_callbr>` instruction. The attribute consists of a 2255 comma separated list of mangled names. The order of the list does 2256 not imply preference (it is logically a set). The compiler is free 2257 to pick any listed vector function of its choosing. 2258 2259 The syntax for the mangled names is as follows::: 2260 2261 _ZGV<isa><mask><vlen><parameters>_<scalar_name>[(<vector_redirection>)] 2262 2263 When present, the attribute informs the compiler that the function 2264 ``<scalar_name>`` has a corresponding vector variant that can be 2265 used to perform the concurrent invocation of ``<scalar_name>`` on 2266 vectors. The shape of the vector function is described by the 2267 tokens between the prefix ``_ZGV`` and the ``<scalar_name>`` 2268 token. The standard name of the vector function is 2269 ``_ZGV<isa><mask><vlen><parameters>_<scalar_name>``. When present, 2270 the optional token ``(<vector_redirection>)`` informs the compiler 2271 that a custom name is provided in addition to the standard one 2272 (custom names can be provided for example via the use of ``declare 2273 variant`` in OpenMP 5.0). The declaration of the variant must be 2274 present in the IR Module. The signature of the vector variant is 2275 determined by the rules of the Vector Function ABI (VFABI) 2276 specifications of the target. For Arm and X86, the VFABI can be 2277 found at https://github.com/ARM-software/abi-aa and 2278 https://software.intel.com/content/www/us/en/develop/download/vector-simd-function-abi.html, 2279 respectively. 2280 2281 For X86 and Arm targets, the values of the tokens in the standard 2282 name are those that are defined in the VFABI. LLVM has an internal 2283 ``<isa>`` token that can be used to create scalar-to-vector 2284 mappings for functions that are not directly associated to any of 2285 the target ISAs (for example, some of the mappings stored in the 2286 TargetLibraryInfo). Valid values for the ``<isa>`` token are::: 2287 2288 <isa>:= b | c | d | e -> X86 SSE, AVX, AVX2, AVX512 2289 | n | s -> Armv8 Advanced SIMD, SVE 2290 | __LLVM__ -> Internal LLVM Vector ISA 2291 2292 For all targets currently supported (x86, Arm and Internal LLVM), 2293 the remaining tokens can have the following values::: 2294 2295 <mask>:= M | N -> mask | no mask 2296 2297 <vlen>:= number -> number of lanes 2298 | x -> VLA (Vector Length Agnostic) 2299 2300 <parameters>:= v -> vector 2301 | l | l <number> -> linear 2302 | R | R <number> -> linear with ref modifier 2303 | L | L <number> -> linear with val modifier 2304 | U | U <number> -> linear with uval modifier 2305 | ls <pos> -> runtime linear 2306 | Rs <pos> -> runtime linear with ref modifier 2307 | Ls <pos> -> runtime linear with val modifier 2308 | Us <pos> -> runtime linear with uval modifier 2309 | u -> uniform 2310 2311 <scalar_name>:= name of the scalar function 2312 2313 <vector_redirection>:= optional, custom name of the vector function 2314 2315``preallocated(<ty>)`` 2316 This attribute is required on calls to ``llvm.call.preallocated.arg`` 2317 and cannot be used on any other call. See 2318 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` for more 2319 details. 2320 2321.. _glattrs: 2322 2323Global Attributes 2324----------------- 2325 2326Attributes may be set to communicate additional information about a global variable. 2327Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable 2328are grouped into a single :ref:`attribute group <attrgrp>`. 2329 2330``no_sanitize_address`` 2331 This attribute indicates that the global variable should not have 2332 AddressSanitizer instrumentation applied to it, because it was annotated 2333 with `__attribute__((no_sanitize("address")))`, 2334 `__attribute__((disable_sanitizer_instrumentation))`, or included in the 2335 `-fsanitize-ignorelist` file. 2336``no_sanitize_hwaddress`` 2337 This attribute indicates that the global variable should not have 2338 HWAddressSanitizer instrumentation applied to it, because it was annotated 2339 with `__attribute__((no_sanitize("hwaddress")))`, 2340 `__attribute__((disable_sanitizer_instrumentation))`, or included in the 2341 `-fsanitize-ignorelist` file. 2342``sanitize_memtag`` 2343 This attribute indicates that the global variable should have AArch64 memory 2344 tags (MTE) instrumentation applied to it. This attribute causes the 2345 suppression of certain optimisations, like GlobalMerge, as well as ensuring 2346 extra directives are emitted in the assembly and extra bits of metadata are 2347 placed in the object file so that the linker can ensure the accesses are 2348 protected by MTE. This attribute is added by clang when 2349 `-fsanitize=memtag-globals` is provided, as long as the global is not marked 2350 with `__attribute__((no_sanitize("memtag")))`, 2351 `__attribute__((disable_sanitizer_instrumentation))`, or included in the 2352 `-fsanitize-ignorelist` file. The AArch64 Globals Tagging pass may remove 2353 this attribute when it's not possible to tag the global (e.g. it's a TLS 2354 variable). 2355``sanitize_address_dyninit`` 2356 This attribute indicates that the global variable, when instrumented with 2357 AddressSanitizer, should be checked for ODR violations. This attribute is 2358 applied to global variables that are dynamically initialized according to 2359 C++ rules. 2360 2361.. _opbundles: 2362 2363Operand Bundles 2364--------------- 2365 2366Operand bundles are tagged sets of SSA values that can be associated 2367with certain LLVM instructions (currently only ``call`` s and 2368``invoke`` s). In a way they are like metadata, but dropping them is 2369incorrect and will change program semantics. 2370 2371Syntax:: 2372 2373 operand bundle set ::= '[' operand bundle (, operand bundle )* ']' 2374 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')' 2375 bundle operand ::= SSA value 2376 tag ::= string constant 2377 2378Operand bundles are **not** part of a function's signature, and a 2379given function may be called from multiple places with different kinds 2380of operand bundles. This reflects the fact that the operand bundles 2381are conceptually a part of the ``call`` (or ``invoke``), not the 2382callee being dispatched to. 2383 2384Operand bundles are a generic mechanism intended to support 2385runtime-introspection-like functionality for managed languages. While 2386the exact semantics of an operand bundle depend on the bundle tag, 2387there are certain limitations to how much the presence of an operand 2388bundle can influence the semantics of a program. These restrictions 2389are described as the semantics of an "unknown" operand bundle. As 2390long as the behavior of an operand bundle is describable within these 2391restrictions, LLVM does not need to have special knowledge of the 2392operand bundle to not miscompile programs containing it. 2393 2394- The bundle operands for an unknown operand bundle escape in unknown 2395 ways before control is transferred to the callee or invokee. 2396- Calls and invokes with operand bundles have unknown read / write 2397 effect on the heap on entry and exit (even if the call target is 2398 ``readnone`` or ``readonly``), unless they're overridden with 2399 callsite specific attributes. 2400- An operand bundle at a call site cannot change the implementation 2401 of the called function. Inter-procedural optimizations work as 2402 usual as long as they take into account the first two properties. 2403 2404More specific types of operand bundles are described below. 2405 2406.. _deopt_opbundles: 2407 2408Deoptimization Operand Bundles 2409^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2410 2411Deoptimization operand bundles are characterized by the ``"deopt"`` 2412operand bundle tag. These operand bundles represent an alternate 2413"safe" continuation for the call site they're attached to, and can be 2414used by a suitable runtime to deoptimize the compiled frame at the 2415specified call site. There can be at most one ``"deopt"`` operand 2416bundle attached to a call site. Exact details of deoptimization is 2417out of scope for the language reference, but it usually involves 2418rewriting a compiled frame into a set of interpreted frames. 2419 2420From the compiler's perspective, deoptimization operand bundles make 2421the call sites they're attached to at least ``readonly``. They read 2422through all of their pointer typed operands (even if they're not 2423otherwise escaped) and the entire visible heap. Deoptimization 2424operand bundles do not capture their operands except during 2425deoptimization, in which case control will not be returned to the 2426compiled frame. 2427 2428The inliner knows how to inline through calls that have deoptimization 2429operand bundles. Just like inlining through a normal call site 2430involves composing the normal and exceptional continuations, inlining 2431through a call site with a deoptimization operand bundle needs to 2432appropriately compose the "safe" deoptimization continuation. The 2433inliner does this by prepending the parent's deoptimization 2434continuation to every deoptimization continuation in the inlined body. 2435E.g. inlining ``@f`` into ``@g`` in the following example 2436 2437.. code-block:: llvm 2438 2439 define void @f() { 2440 call void @x() ;; no deopt state 2441 call void @y() [ "deopt"(i32 10) ] 2442 call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ] 2443 ret void 2444 } 2445 2446 define void @g() { 2447 call void @f() [ "deopt"(i32 20) ] 2448 ret void 2449 } 2450 2451will result in 2452 2453.. code-block:: llvm 2454 2455 define void @g() { 2456 call void @x() ;; still no deopt state 2457 call void @y() [ "deopt"(i32 20, i32 10) ] 2458 call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ] 2459 ret void 2460 } 2461 2462It is the frontend's responsibility to structure or encode the 2463deoptimization state in a way that syntactically prepending the 2464caller's deoptimization state to the callee's deoptimization state is 2465semantically equivalent to composing the caller's deoptimization 2466continuation after the callee's deoptimization continuation. 2467 2468.. _ob_funclet: 2469 2470Funclet Operand Bundles 2471^^^^^^^^^^^^^^^^^^^^^^^ 2472 2473Funclet operand bundles are characterized by the ``"funclet"`` 2474operand bundle tag. These operand bundles indicate that a call site 2475is within a particular funclet. There can be at most one 2476``"funclet"`` operand bundle attached to a call site and it must have 2477exactly one bundle operand. 2478 2479If any funclet EH pads have been "entered" but not "exited" (per the 2480`description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_), 2481it is undefined behavior to execute a ``call`` or ``invoke`` which: 2482 2483* does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind 2484 intrinsic, or 2485* has a ``"funclet"`` bundle whose operand is not the most-recently-entered 2486 not-yet-exited funclet EH pad. 2487 2488Similarly, if no funclet EH pads have been entered-but-not-yet-exited, 2489executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior. 2490 2491GC Transition Operand Bundles 2492^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2493 2494GC transition operand bundles are characterized by the 2495``"gc-transition"`` operand bundle tag. These operand bundles mark a 2496call as a transition between a function with one GC strategy to a 2497function with a different GC strategy. If coordinating the transition 2498between GC strategies requires additional code generation at the call 2499site, these bundles may contain any values that are needed by the 2500generated code. For more details, see :ref:`GC Transitions 2501<gc_transition_args>`. 2502 2503The bundle contain an arbitrary list of Values which need to be passed 2504to GC transition code. They will be lowered and passed as operands to 2505the appropriate GC_TRANSITION nodes in the selection DAG. It is assumed 2506that these arguments must be available before and after (but not 2507necessarily during) the execution of the callee. 2508 2509.. _assume_opbundles: 2510 2511Assume Operand Bundles 2512^^^^^^^^^^^^^^^^^^^^^^ 2513 2514Operand bundles on an :ref:`llvm.assume <int_assume>` allows representing 2515assumptions that a :ref:`parameter attribute <paramattrs>` or a 2516:ref:`function attribute <fnattrs>` holds for a certain value at a certain 2517location. Operand bundles enable assumptions that are either hard or impossible 2518to represent as a boolean argument of an :ref:`llvm.assume <int_assume>`. 2519 2520An assume operand bundle has the form: 2521 2522:: 2523 2524 "<tag>"([ <holds for value> [, <attribute argument>] ]) 2525 2526* The tag of the operand bundle is usually the name of attribute that can be 2527 assumed to hold. It can also be `ignore`, this tag doesn't contain any 2528 information and should be ignored. 2529* The first argument if present is the value for which the attribute hold. 2530* The second argument if present is an argument of the attribute. 2531 2532If there are no arguments the attribute is a property of the call location. 2533 2534For example: 2535 2536.. code-block:: llvm 2537 2538 call void @llvm.assume(i1 true) ["align"(i32* %val, i32 8)] 2539 2540allows the optimizer to assume that at location of call to 2541:ref:`llvm.assume <int_assume>` ``%val`` has an alignment of at least 8. 2542 2543.. code-block:: llvm 2544 2545 call void @llvm.assume(i1 %cond) ["cold"(), "nonnull"(i64* %val)] 2546 2547allows the optimizer to assume that the :ref:`llvm.assume <int_assume>` 2548call location is cold and that ``%val`` may not be null. 2549 2550Just like for the argument of :ref:`llvm.assume <int_assume>`, if any of the 2551provided guarantees are violated at runtime the behavior is undefined. 2552 2553While attributes expect constant arguments, assume operand bundles may be 2554provided a dynamic value, for example: 2555 2556.. code-block:: llvm 2557 2558 call void @llvm.assume(i1 true) ["align"(i32* %val, i32 %align)] 2559 2560If the operand bundle value violates any requirements on the attribute value, 2561the behavior is undefined, unless one of the following exceptions applies: 2562 2563* ``"assume"`` operand bundles may specify a non-power-of-two alignment 2564 (including a zero alignment). If this is the case, then the pointer value 2565 must be a null pointer, otherwise the behavior is undefined. 2566 2567Even if the assumed property can be encoded as a boolean value, like 2568``nonnull``, using operand bundles to express the property can still have 2569benefits: 2570 2571* Attributes that can be expressed via operand bundles are directly the 2572 property that the optimizer uses and cares about. Encoding attributes as 2573 operand bundles removes the need for an instruction sequence that represents 2574 the property (e.g., `icmp ne i32* %p, null` for `nonnull`) and for the 2575 optimizer to deduce the property from that instruction sequence. 2576* Expressing the property using operand bundles makes it easy to identify the 2577 use of the value as a use in an :ref:`llvm.assume <int_assume>`. This then 2578 simplifies and improves heuristics, e.g., for use "use-sensitive" 2579 optimizations. 2580 2581.. _ob_preallocated: 2582 2583Preallocated Operand Bundles 2584^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2585 2586Preallocated operand bundles are characterized by the ``"preallocated"`` 2587operand bundle tag. These operand bundles allow separation of the allocation 2588of the call argument memory from the call site. This is necessary to pass 2589non-trivially copyable objects by value in a way that is compatible with MSVC 2590on some targets. There can be at most one ``"preallocated"`` operand bundle 2591attached to a call site and it must have exactly one bundle operand, which is 2592a token generated by ``@llvm.call.preallocated.setup``. A call with this 2593operand bundle should not adjust the stack before entering the function, as 2594that will have been done by one of the ``@llvm.call.preallocated.*`` intrinsics. 2595 2596.. code-block:: llvm 2597 2598 %foo = type { i64, i32 } 2599 2600 ... 2601 2602 %t = call token @llvm.call.preallocated.setup(i32 1) 2603 %a = call i8* @llvm.call.preallocated.arg(token %t, i32 0) preallocated(%foo) 2604 %b = bitcast i8* %a to %foo* 2605 ; initialize %b 2606 call void @bar(i32 42, %foo* preallocated(%foo) %b) ["preallocated"(token %t)] 2607 2608.. _ob_gc_live: 2609 2610GC Live Operand Bundles 2611^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2612 2613A "gc-live" operand bundle is only valid on a :ref:`gc.statepoint <gc_statepoint>` 2614intrinsic. The operand bundle must contain every pointer to a garbage collected 2615object which potentially needs to be updated by the garbage collector. 2616 2617When lowered, any relocated value will be recorded in the corresponding 2618:ref:`stackmap entry <statepoint-stackmap-format>`. See the intrinsic description 2619for further details. 2620 2621ObjC ARC Attached Call Operand Bundles 2622^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2623 2624A ``"clang.arc.attachedcall"`` operand bundle on a call indicates the call is 2625implicitly followed by a marker instruction and a call to an ObjC runtime 2626function that uses the result of the call. The operand bundle takes a mandatory 2627pointer to the runtime function (``@objc_retainAutoreleasedReturnValue`` or 2628``@objc_unsafeClaimAutoreleasedReturnValue``). 2629The return value of a call with this bundle is used by a call to 2630``@llvm.objc.clang.arc.noop.use`` unless the called function's return type is 2631void, in which case the operand bundle is ignored. 2632 2633.. code-block:: llvm 2634 2635 ; The marker instruction and a runtime function call are inserted after the call 2636 ; to @foo. 2637 call i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @objc_retainAutoreleasedReturnValue) ] 2638 call i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @objc_unsafeClaimAutoreleasedReturnValue) ] 2639 2640The operand bundle is needed to ensure the call is immediately followed by the 2641marker instruction and the ObjC runtime call in the final output. 2642 2643.. _ob_ptrauth: 2644 2645Pointer Authentication Operand Bundles 2646^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2647 2648Pointer Authentication operand bundles are characterized by the 2649``"ptrauth"`` operand bundle tag. They are described in the 2650`Pointer Authentication <PointerAuth.html#operand-bundle>`__ document. 2651 2652.. _moduleasm: 2653 2654Module-Level Inline Assembly 2655---------------------------- 2656 2657Modules may contain "module-level inline asm" blocks, which corresponds 2658to the GCC "file scope inline asm" blocks. These blocks are internally 2659concatenated by LLVM and treated as a single unit, but may be separated 2660in the ``.ll`` file if desired. The syntax is very simple: 2661 2662.. code-block:: llvm 2663 2664 module asm "inline asm code goes here" 2665 module asm "more can go here" 2666 2667The strings can contain any character by escaping non-printable 2668characters. The escape sequence used is simply "\\xx" where "xx" is the 2669two digit hex code for the number. 2670 2671Note that the assembly string *must* be parseable by LLVM's integrated assembler 2672(unless it is disabled), even when emitting a ``.s`` file. 2673 2674.. _langref_datalayout: 2675 2676Data Layout 2677----------- 2678 2679A module may specify a target specific data layout string that specifies 2680how data is to be laid out in memory. The syntax for the data layout is 2681simply: 2682 2683.. code-block:: llvm 2684 2685 target datalayout = "layout specification" 2686 2687The *layout specification* consists of a list of specifications 2688separated by the minus sign character ('-'). Each specification starts 2689with a letter and may include other information after the letter to 2690define some aspect of the data layout. The specifications accepted are 2691as follows: 2692 2693``E`` 2694 Specifies that the target lays out data in big-endian form. That is, 2695 the bits with the most significance have the lowest address 2696 location. 2697``e`` 2698 Specifies that the target lays out data in little-endian form. That 2699 is, the bits with the least significance have the lowest address 2700 location. 2701``S<size>`` 2702 Specifies the natural alignment of the stack in bits. Alignment 2703 promotion of stack variables is limited to the natural stack 2704 alignment to avoid dynamic stack realignment. The stack alignment 2705 must be a multiple of 8-bits. If omitted, the natural stack 2706 alignment defaults to "unspecified", which does not prevent any 2707 alignment promotions. 2708``P<address space>`` 2709 Specifies the address space that corresponds to program memory. 2710 Harvard architectures can use this to specify what space LLVM 2711 should place things such as functions into. If omitted, the 2712 program memory space defaults to the default address space of 0, 2713 which corresponds to a Von Neumann architecture that has code 2714 and data in the same space. 2715``G<address space>`` 2716 Specifies the address space to be used by default when creating global 2717 variables. If omitted, the globals address space defaults to the default 2718 address space 0. 2719 Note: variable declarations without an address space are always created in 2720 address space 0, this property only affects the default value to be used 2721 when creating globals without additional contextual information (e.g. in 2722 LLVM passes). 2723``A<address space>`` 2724 Specifies the address space of objects created by '``alloca``'. 2725 Defaults to the default address space of 0. 2726``p[n]:<size>:<abi>[:<pref>][:<idx>]`` 2727 This specifies the *size* of a pointer and its ``<abi>`` and 2728 ``<pref>``\erred alignments for address space ``n``. ``<pref>`` is optional 2729 and defaults to ``<abi>``. The fourth parameter ``<idx>`` is the size of the 2730 index that used for address calculation. If not 2731 specified, the default index size is equal to the pointer size. All sizes 2732 are in bits. The address space, ``n``, is optional, and if not specified, 2733 denotes the default address space 0. The value of ``n`` must be 2734 in the range [1,2^23). 2735``i<size>:<abi>[:<pref>]`` 2736 This specifies the alignment for an integer type of a given bit 2737 ``<size>``. The value of ``<size>`` must be in the range [1,2^23). 2738 ``<pref>`` is optional and defaults to ``<abi>``. 2739``v<size>:<abi>[:<pref>]`` 2740 This specifies the alignment for a vector type of a given bit 2741 ``<size>``. The value of ``<size>`` must be in the range [1,2^23). 2742 ``<pref>`` is optional and defaults to ``<abi>``. 2743``f<size>:<abi>[:<pref>]`` 2744 This specifies the alignment for a floating-point type of a given bit 2745 ``<size>``. Only values of ``<size>`` that are supported by the target 2746 will work. 32 (float) and 64 (double) are supported on all targets; 80 2747 or 128 (different flavors of long double) are also supported on some 2748 targets. The value of ``<size>`` must be in the range [1,2^23). 2749 ``<pref>`` is optional and defaults to ``<abi>``. 2750``a:<abi>[:<pref>]`` 2751 This specifies the alignment for an object of aggregate type. 2752 ``<pref>`` is optional and defaults to ``<abi>``. 2753``F<type><abi>`` 2754 This specifies the alignment for function pointers. 2755 The options for ``<type>`` are: 2756 2757 * ``i``: The alignment of function pointers is independent of the alignment 2758 of functions, and is a multiple of ``<abi>``. 2759 * ``n``: The alignment of function pointers is a multiple of the explicit 2760 alignment specified on the function, and is a multiple of ``<abi>``. 2761``m:<mangling>`` 2762 If present, specifies that llvm names are mangled in the output. Symbols 2763 prefixed with the mangling escape character ``\01`` are passed through 2764 directly to the assembler without the escape character. The mangling style 2765 options are 2766 2767 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix. 2768 * ``l``: GOFF mangling: Private symbols get a ``@`` prefix. 2769 * ``m``: Mips mangling: Private symbols get a ``$`` prefix. 2770 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other 2771 symbols get a ``_`` prefix. 2772 * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix. 2773 Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``, 2774 ``__fastcall``, and ``__vectorcall`` have custom mangling that appends 2775 ``@N`` where N is the number of bytes used to pass parameters. C++ symbols 2776 starting with ``?`` are not mangled in any way. 2777 * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C 2778 symbols do not receive a ``_`` prefix. 2779 * ``a``: XCOFF mangling: Private symbols get a ``L..`` prefix. 2780``n<size1>:<size2>:<size3>...`` 2781 This specifies a set of native integer widths for the target CPU in 2782 bits. For example, it might contain ``n32`` for 32-bit PowerPC, 2783 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of 2784 this set are considered to support most general arithmetic operations 2785 efficiently. 2786``ni:<address space0>:<address space1>:<address space2>...`` 2787 This specifies pointer types with the specified address spaces 2788 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0`` 2789 address space cannot be specified as non-integral. 2790 2791On every specification that takes a ``<abi>:<pref>``, specifying the 2792``<pref>`` alignment is optional. If omitted, the preceding ``:`` 2793should be omitted too and ``<pref>`` will be equal to ``<abi>``. 2794 2795When constructing the data layout for a given target, LLVM starts with a 2796default set of specifications which are then (possibly) overridden by 2797the specifications in the ``datalayout`` keyword. The default 2798specifications are given in this list: 2799 2800- ``e`` - little endian 2801- ``p:64:64:64`` - 64-bit pointers with 64-bit alignment. 2802- ``p[n]:64:64:64`` - Other address spaces are assumed to be the 2803 same as the default address space. 2804- ``S0`` - natural stack alignment is unspecified 2805- ``i1:8:8`` - i1 is 8-bit (byte) aligned 2806- ``i8:8:8`` - i8 is 8-bit (byte) aligned 2807- ``i16:16:16`` - i16 is 16-bit aligned 2808- ``i32:32:32`` - i32 is 32-bit aligned 2809- ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred 2810 alignment of 64-bits 2811- ``f16:16:16`` - half is 16-bit aligned 2812- ``f32:32:32`` - float is 32-bit aligned 2813- ``f64:64:64`` - double is 64-bit aligned 2814- ``f128:128:128`` - quad is 128-bit aligned 2815- ``v64:64:64`` - 64-bit vector is 64-bit aligned 2816- ``v128:128:128`` - 128-bit vector is 128-bit aligned 2817- ``a:0:64`` - aggregates are 64-bit aligned 2818 2819When LLVM is determining the alignment for a given type, it uses the 2820following rules: 2821 2822#. If the type sought is an exact match for one of the specifications, 2823 that specification is used. 2824#. If no match is found, and the type sought is an integer type, then 2825 the smallest integer type that is larger than the bitwidth of the 2826 sought type is used. If none of the specifications are larger than 2827 the bitwidth then the largest integer type is used. For example, 2828 given the default specifications above, the i7 type will use the 2829 alignment of i8 (next largest) while both i65 and i256 will use the 2830 alignment of i64 (largest specified). 2831 2832The function of the data layout string may not be what you expect. 2833Notably, this is not a specification from the frontend of what alignment 2834the code generator should use. 2835 2836Instead, if specified, the target data layout is required to match what 2837the ultimate *code generator* expects. This string is used by the 2838mid-level optimizers to improve code, and this only works if it matches 2839what the ultimate code generator uses. There is no way to generate IR 2840that does not embed this target-specific detail into the IR. If you 2841don't specify the string, the default specifications will be used to 2842generate a Data Layout and the optimization phases will operate 2843accordingly and introduce target specificity into the IR with respect to 2844these default specifications. 2845 2846.. _langref_triple: 2847 2848Target Triple 2849------------- 2850 2851A module may specify a target triple string that describes the target 2852host. The syntax for the target triple is simply: 2853 2854.. code-block:: llvm 2855 2856 target triple = "x86_64-apple-macosx10.7.0" 2857 2858The *target triple* string consists of a series of identifiers delimited 2859by the minus sign character ('-'). The canonical forms are: 2860 2861:: 2862 2863 ARCHITECTURE-VENDOR-OPERATING_SYSTEM 2864 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT 2865 2866This information is passed along to the backend so that it generates 2867code for the proper architecture. It's possible to override this on the 2868command line with the ``-mtriple`` command line option. 2869 2870.. _objectlifetime: 2871 2872Object Lifetime 2873---------------------- 2874 2875A memory object, or simply object, is a region of a memory space that is 2876reserved by a memory allocation such as :ref:`alloca <i_alloca>`, heap 2877allocation calls, and global variable definitions. 2878Once it is allocated, the bytes stored in the region can only be read or written 2879through a pointer that is :ref:`based on <pointeraliasing>` the allocation 2880value. 2881If a pointer that is not based on the object tries to read or write to the 2882object, it is undefined behavior. 2883 2884A lifetime of a memory object is a property that decides its accessibility. 2885Unless stated otherwise, a memory object is alive since its allocation, and 2886dead after its deallocation. 2887It is undefined behavior to access a memory object that isn't alive, but 2888operations that don't dereference it such as 2889:ref:`getelementptr <i_getelementptr>`, :ref:`ptrtoint <i_ptrtoint>` and 2890:ref:`icmp <i_icmp>` return a valid result. 2891This explains code motion of these instructions across operations that 2892impact the object's lifetime. 2893A stack object's lifetime can be explicitly specified using 2894:ref:`llvm.lifetime.start <int_lifestart>` and 2895:ref:`llvm.lifetime.end <int_lifeend>` intrinsic function calls. 2896 2897.. _pointeraliasing: 2898 2899Pointer Aliasing Rules 2900---------------------- 2901 2902Any memory access must be done through a pointer value associated with 2903an address range of the memory access, otherwise the behavior is 2904undefined. Pointer values are associated with address ranges according 2905to the following rules: 2906 2907- A pointer value is associated with the addresses associated with any 2908 value it is *based* on. 2909- An address of a global variable is associated with the address range 2910 of the variable's storage. 2911- The result value of an allocation instruction is associated with the 2912 address range of the allocated storage. 2913- A null pointer in the default address-space is associated with no 2914 address. 2915- An :ref:`undef value <undefvalues>` in *any* address-space is 2916 associated with no address. 2917- An integer constant other than zero or a pointer value returned from 2918 a function not defined within LLVM may be associated with address 2919 ranges allocated through mechanisms other than those provided by 2920 LLVM. Such ranges shall not overlap with any ranges of addresses 2921 allocated by mechanisms provided by LLVM. 2922 2923A pointer value is *based* on another pointer value according to the 2924following rules: 2925 2926- A pointer value formed from a scalar ``getelementptr`` operation is *based* on 2927 the pointer-typed operand of the ``getelementptr``. 2928- The pointer in lane *l* of the result of a vector ``getelementptr`` operation 2929 is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand 2930 of the ``getelementptr``. 2931- The result value of a ``bitcast`` is *based* on the operand of the 2932 ``bitcast``. 2933- A pointer value formed by an ``inttoptr`` is *based* on all pointer 2934 values that contribute (directly or indirectly) to the computation of 2935 the pointer's value. 2936- The "*based* on" relationship is transitive. 2937 2938Note that this definition of *"based"* is intentionally similar to the 2939definition of *"based"* in C99, though it is slightly weaker. 2940 2941LLVM IR does not associate types with memory. The result type of a 2942``load`` merely indicates the size and alignment of the memory from 2943which to load, as well as the interpretation of the value. The first 2944operand type of a ``store`` similarly only indicates the size and 2945alignment of the store. 2946 2947Consequently, type-based alias analysis, aka TBAA, aka 2948``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR. 2949:ref:`Metadata <metadata>` may be used to encode additional information 2950which specialized optimization passes may use to implement type-based 2951alias analysis. 2952 2953.. _pointercapture: 2954 2955Pointer Capture 2956--------------- 2957 2958Given a function call and a pointer that is passed as an argument or stored in 2959the memory before the call, a pointer is *captured* by the call if it makes a 2960copy of any part of the pointer that outlives the call. 2961To be precise, a pointer is captured if one or more of the following conditions 2962hold: 2963 29641. The call stores any bit of the pointer carrying information into a place, 2965 and the stored bits can be read from the place by the caller after this call 2966 exits. 2967 2968.. code-block:: llvm 2969 2970 @glb = global i8* null 2971 @glb2 = global i8* null 2972 @glb3 = global i8* null 2973 @glbi = global i32 0 2974 2975 define i8* @f(i8* %a, i8* %b, i8* %c, i8* %d, i8* %e) { 2976 store i8* %a, i8** @glb ; %a is captured by this call 2977 2978 store i8* %b, i8** @glb2 ; %b isn't captured because the stored value is overwritten by the store below 2979 store i8* null, i8** @glb2 2980 2981 store i8* %c, i8** @glb3 2982 call void @g() ; If @g makes a copy of %c that outlives this call (@f), %c is captured 2983 store i8* null, i8** @glb3 2984 2985 %i = ptrtoint i8* %d to i64 2986 %j = trunc i64 %i to i32 2987 store i32 %j, i32* @glbi ; %d is captured 2988 2989 ret i8* %e ; %e is captured 2990 } 2991 29922. The call stores any bit of the pointer carrying information into a place, 2993 and the stored bits can be safely read from the place by another thread via 2994 synchronization. 2995 2996.. code-block:: llvm 2997 2998 @lock = global i1 true 2999 3000 define void @f(i8* %a) { 3001 store i8* %a, i8** @glb 3002 store atomic i1 false, i1* @lock release ; %a is captured because another thread can safely read @glb 3003 store i8* null, i8** @glb 3004 ret void 3005 } 3006 30073. The call's behavior depends on any bit of the pointer carrying information. 3008 3009.. code-block:: llvm 3010 3011 @glb = global i8 0 3012 3013 define void @f(i8* %a) { 3014 %c = icmp eq i8* %a, @glb 3015 br i1 %c, label %BB_EXIT, label %BB_CONTINUE ; escapes %a 3016 BB_EXIT: 3017 call void @exit() 3018 unreachable 3019 BB_CONTINUE: 3020 ret void 3021 } 3022 30234. The pointer is used in a volatile access as its address. 3024 3025 3026.. _volatile: 3027 3028Volatile Memory Accesses 3029------------------------ 3030 3031Certain memory accesses, such as :ref:`load <i_load>`'s, 3032:ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be 3033marked ``volatile``. The optimizers must not change the number of 3034volatile operations or change their order of execution relative to other 3035volatile operations. The optimizers *may* change the order of volatile 3036operations relative to non-volatile operations. This is not Java's 3037"volatile" and has no cross-thread synchronization behavior. 3038 3039A volatile load or store may have additional target-specific semantics. 3040Any volatile operation can have side effects, and any volatile operation 3041can read and/or modify state which is not accessible via a regular load 3042or store in this module. Volatile operations may use addresses which do 3043not point to memory (like MMIO registers). This means the compiler may 3044not use a volatile operation to prove a non-volatile access to that 3045address has defined behavior. 3046 3047The allowed side-effects for volatile accesses are limited. If a 3048non-volatile store to a given address would be legal, a volatile 3049operation may modify the memory at that address. A volatile operation 3050may not modify any other memory accessible by the module being compiled. 3051A volatile operation may not call any code in the current module. 3052 3053The compiler may assume execution will continue after a volatile operation, 3054so operations which modify memory or may have undefined behavior can be 3055hoisted past a volatile operation. 3056 3057As an exception to the preceding rule, the compiler may not assume execution 3058will continue after a volatile store operation. This restriction is necessary 3059to support the somewhat common pattern in C of intentionally storing to an 3060invalid pointer to crash the program. In the future, it might make sense to 3061allow frontends to control this behavior. 3062 3063IR-level volatile loads and stores cannot safely be optimized into llvm.memcpy 3064or llvm.memmove intrinsics even when those intrinsics are flagged volatile. 3065Likewise, the backend should never split or merge target-legal volatile 3066load/store instructions. Similarly, IR-level volatile loads and stores cannot 3067change from integer to floating-point or vice versa. 3068 3069.. admonition:: Rationale 3070 3071 Platforms may rely on volatile loads and stores of natively supported 3072 data width to be executed as single instruction. For example, in C 3073 this holds for an l-value of volatile primitive type with native 3074 hardware support, but not necessarily for aggregate types. The 3075 frontend upholds these expectations, which are intentionally 3076 unspecified in the IR. The rules above ensure that IR transformations 3077 do not violate the frontend's contract with the language. 3078 3079.. _memmodel: 3080 3081Memory Model for Concurrent Operations 3082-------------------------------------- 3083 3084The LLVM IR does not define any way to start parallel threads of 3085execution or to register signal handlers. Nonetheless, there are 3086platform-specific ways to create them, and we define LLVM IR's behavior 3087in their presence. This model is inspired by the C++0x memory model. 3088 3089For a more informal introduction to this model, see the :doc:`Atomics`. 3090 3091We define a *happens-before* partial order as the least partial order 3092that 3093 3094- Is a superset of single-thread program order, and 3095- When a *synchronizes-with* ``b``, includes an edge from ``a`` to 3096 ``b``. *Synchronizes-with* pairs are introduced by platform-specific 3097 techniques, like pthread locks, thread creation, thread joining, 3098 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering 3099 Constraints <ordering>`). 3100 3101Note that program order does not introduce *happens-before* edges 3102between a thread and signals executing inside that thread. 3103 3104Every (defined) read operation (load instructions, memcpy, atomic 3105loads/read-modify-writes, etc.) R reads a series of bytes written by 3106(defined) write operations (store instructions, atomic 3107stores/read-modify-writes, memcpy, etc.). For the purposes of this 3108section, initialized globals are considered to have a write of the 3109initializer which is atomic and happens before any other read or write 3110of the memory in question. For each byte of a read R, R\ :sub:`byte` 3111may see any write to the same byte, except: 3112 3113- If write\ :sub:`1` happens before write\ :sub:`2`, and 3114 write\ :sub:`2` happens before R\ :sub:`byte`, then 3115 R\ :sub:`byte` does not see write\ :sub:`1`. 3116- If R\ :sub:`byte` happens before write\ :sub:`3`, then 3117 R\ :sub:`byte` does not see write\ :sub:`3`. 3118 3119Given that definition, R\ :sub:`byte` is defined as follows: 3120 3121- If R is volatile, the result is target-dependent. (Volatile is 3122 supposed to give guarantees which can support ``sig_atomic_t`` in 3123 C/C++, and may be used for accesses to addresses that do not behave 3124 like normal memory. It does not generally provide cross-thread 3125 synchronization.) 3126- Otherwise, if there is no write to the same byte that happens before 3127 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte. 3128- Otherwise, if R\ :sub:`byte` may see exactly one write, 3129 R\ :sub:`byte` returns the value written by that write. 3130- Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may 3131 see are atomic, it chooses one of the values written. See the :ref:`Atomic 3132 Memory Ordering Constraints <ordering>` section for additional 3133 constraints on how the choice is made. 3134- Otherwise R\ :sub:`byte` returns ``undef``. 3135 3136R returns the value composed of the series of bytes it read. This 3137implies that some bytes within the value may be ``undef`` **without** 3138the entire value being ``undef``. Note that this only defines the 3139semantics of the operation; it doesn't mean that targets will emit more 3140than one instruction to read the series of bytes. 3141 3142Note that in cases where none of the atomic intrinsics are used, this 3143model places only one restriction on IR transformations on top of what 3144is required for single-threaded execution: introducing a store to a byte 3145which might not otherwise be stored is not allowed in general. 3146(Specifically, in the case where another thread might write to and read 3147from an address, introducing a store can change a load that may see 3148exactly one write into a load that may see multiple writes.) 3149 3150.. _ordering: 3151 3152Atomic Memory Ordering Constraints 3153---------------------------------- 3154 3155Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`, 3156:ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`, 3157:ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take 3158ordering parameters that determine which other atomic instructions on 3159the same address they *synchronize with*. These semantics are borrowed 3160from Java and C++0x, but are somewhat more colloquial. If these 3161descriptions aren't precise enough, check those specs (see spec 3162references in the :doc:`atomics guide <Atomics>`). 3163:ref:`fence <i_fence>` instructions treat these orderings somewhat 3164differently since they don't take an address. See that instruction's 3165documentation for details. 3166 3167For a simpler introduction to the ordering constraints, see the 3168:doc:`Atomics`. 3169 3170``unordered`` 3171 The set of values that can be read is governed by the happens-before 3172 partial order. A value cannot be read unless some operation wrote 3173 it. This is intended to provide a guarantee strong enough to model 3174 Java's non-volatile shared variables. This ordering cannot be 3175 specified for read-modify-write operations; it is not strong enough 3176 to make them atomic in any interesting way. 3177``monotonic`` 3178 In addition to the guarantees of ``unordered``, there is a single 3179 total order for modifications by ``monotonic`` operations on each 3180 address. All modification orders must be compatible with the 3181 happens-before order. There is no guarantee that the modification 3182 orders can be combined to a global total order for the whole program 3183 (and this often will not be possible). The read in an atomic 3184 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and 3185 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification 3186 order immediately before the value it writes. If one atomic read 3187 happens before another atomic read of the same address, the later 3188 read must see the same value or a later value in the address's 3189 modification order. This disallows reordering of ``monotonic`` (or 3190 stronger) operations on the same address. If an address is written 3191 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally 3192 read that address repeatedly, the other threads must eventually see 3193 the write. This corresponds to the C++0x/C1x 3194 ``memory_order_relaxed``. 3195``acquire`` 3196 In addition to the guarantees of ``monotonic``, a 3197 *synchronizes-with* edge may be formed with a ``release`` operation. 3198 This is intended to model C++'s ``memory_order_acquire``. 3199``release`` 3200 In addition to the guarantees of ``monotonic``, if this operation 3201 writes a value which is subsequently read by an ``acquire`` 3202 operation, it *synchronizes-with* that operation. (This isn't a 3203 complete description; see the C++0x definition of a release 3204 sequence.) This corresponds to the C++0x/C1x 3205 ``memory_order_release``. 3206``acq_rel`` (acquire+release) 3207 Acts as both an ``acquire`` and ``release`` operation on its 3208 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``. 3209``seq_cst`` (sequentially consistent) 3210 In addition to the guarantees of ``acq_rel`` (``acquire`` for an 3211 operation that only reads, ``release`` for an operation that only 3212 writes), there is a global total order on all 3213 sequentially-consistent operations on all addresses, which is 3214 consistent with the *happens-before* partial order and with the 3215 modification orders of all the affected addresses. Each 3216 sequentially-consistent read sees the last preceding write to the 3217 same address in this global order. This corresponds to the C++0x/C1x 3218 ``memory_order_seq_cst`` and Java volatile. 3219 3220.. _syncscope: 3221 3222If an atomic operation is marked ``syncscope("singlethread")``, it only 3223*synchronizes with* and only participates in the seq\_cst total orderings of 3224other operations running in the same thread (for example, in signal handlers). 3225 3226If an atomic operation is marked ``syncscope("<target-scope>")``, where 3227``<target-scope>`` is a target specific synchronization scope, then it is target 3228dependent if it *synchronizes with* and participates in the seq\_cst total 3229orderings of other operations. 3230 3231Otherwise, an atomic operation that is not marked ``syncscope("singlethread")`` 3232or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the 3233seq\_cst total orderings of other operations that are not marked 3234``syncscope("singlethread")`` or ``syncscope("<target-scope>")``. 3235 3236.. _floatenv: 3237 3238Floating-Point Environment 3239-------------------------- 3240 3241The default LLVM floating-point environment assumes that floating-point 3242instructions do not have side effects. Results assume the round-to-nearest 3243rounding mode. No floating-point exception state is maintained in this 3244environment. Therefore, there is no attempt to create or preserve invalid 3245operation (SNaN) or division-by-zero exceptions. 3246 3247The benefit of this exception-free assumption is that floating-point 3248operations may be speculated freely without any other fast-math relaxations 3249to the floating-point model. 3250 3251Code that requires different behavior than this should use the 3252:ref:`Constrained Floating-Point Intrinsics <constrainedfp>`. 3253 3254.. _fastmath: 3255 3256Fast-Math Flags 3257--------------- 3258 3259LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`, 3260:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`, 3261:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`, 3262:ref:`select <i_select>` and :ref:`call <i_call>` 3263may use the following flags to enable otherwise unsafe 3264floating-point transformations. 3265 3266``nnan`` 3267 No NaNs - Allow optimizations to assume the arguments and result are not 3268 NaN. If an argument is a nan, or the result would be a nan, it produces 3269 a :ref:`poison value <poisonvalues>` instead. 3270 3271``ninf`` 3272 No Infs - Allow optimizations to assume the arguments and result are not 3273 +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it 3274 produces a :ref:`poison value <poisonvalues>` instead. 3275 3276``nsz`` 3277 No Signed Zeros - Allow optimizations to treat the sign of a zero 3278 argument or result as insignificant. This does not imply that -0.0 3279 is poison and/or guaranteed to not exist in the operation. 3280 3281``arcp`` 3282 Allow Reciprocal - Allow optimizations to use the reciprocal of an 3283 argument rather than perform division. 3284 3285``contract`` 3286 Allow floating-point contraction (e.g. fusing a multiply followed by an 3287 addition into a fused multiply-and-add). This does not enable reassociating 3288 to form arbitrary contractions. For example, ``(a*b) + (c*d) + e`` can not 3289 be transformed into ``(a*b) + ((c*d) + e)`` to create two fma operations. 3290 3291``afn`` 3292 Approximate functions - Allow substitution of approximate calculations for 3293 functions (sin, log, sqrt, etc). See floating-point intrinsic definitions 3294 for places where this can apply to LLVM's intrinsic math functions. 3295 3296``reassoc`` 3297 Allow reassociation transformations for floating-point instructions. 3298 This may dramatically change results in floating-point. 3299 3300``fast`` 3301 This flag implies all of the others. 3302 3303.. _uselistorder: 3304 3305Use-list Order Directives 3306------------------------- 3307 3308Use-list directives encode the in-memory order of each use-list, allowing the 3309order to be recreated. ``<order-indexes>`` is a comma-separated list of 3310indexes that are assigned to the referenced value's uses. The referenced 3311value's use-list is immediately sorted by these indexes. 3312 3313Use-list directives may appear at function scope or global scope. They are not 3314instructions, and have no effect on the semantics of the IR. When they're at 3315function scope, they must appear after the terminator of the final basic block. 3316 3317If basic blocks have their address taken via ``blockaddress()`` expressions, 3318``uselistorder_bb`` can be used to reorder their use-lists from outside their 3319function's scope. 3320 3321:Syntax: 3322 3323:: 3324 3325 uselistorder <ty> <value>, { <order-indexes> } 3326 uselistorder_bb @function, %block { <order-indexes> } 3327 3328:Examples: 3329 3330:: 3331 3332 define void @foo(i32 %arg1, i32 %arg2) { 3333 entry: 3334 ; ... instructions ... 3335 bb: 3336 ; ... instructions ... 3337 3338 ; At function scope. 3339 uselistorder i32 %arg1, { 1, 0, 2 } 3340 uselistorder label %bb, { 1, 0 } 3341 } 3342 3343 ; At global scope. 3344 uselistorder i32* @global, { 1, 2, 0 } 3345 uselistorder i32 7, { 1, 0 } 3346 uselistorder i32 (i32) @bar, { 1, 0 } 3347 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 } 3348 3349.. _source_filename: 3350 3351Source Filename 3352--------------- 3353 3354The *source filename* string is set to the original module identifier, 3355which will be the name of the compiled source file when compiling from 3356source through the clang front end, for example. It is then preserved through 3357the IR and bitcode. 3358 3359This is currently necessary to generate a consistent unique global 3360identifier for local functions used in profile data, which prepends the 3361source file name to the local function name. 3362 3363The syntax for the source file name is simply: 3364 3365.. code-block:: text 3366 3367 source_filename = "/path/to/source.c" 3368 3369.. _typesystem: 3370 3371Type System 3372=========== 3373 3374The LLVM type system is one of the most important features of the 3375intermediate representation. Being typed enables a number of 3376optimizations to be performed on the intermediate representation 3377directly, without having to do extra analyses on the side before the 3378transformation. A strong type system makes it easier to read the 3379generated code and enables novel analyses and transformations that are 3380not feasible to perform on normal three address code representations. 3381 3382.. _t_void: 3383 3384Void Type 3385--------- 3386 3387:Overview: 3388 3389 3390The void type does not represent any value and has no size. 3391 3392:Syntax: 3393 3394 3395:: 3396 3397 void 3398 3399 3400.. _t_function: 3401 3402Function Type 3403------------- 3404 3405:Overview: 3406 3407 3408The function type can be thought of as a function signature. It consists of a 3409return type and a list of formal parameter types. The return type of a function 3410type is a void type or first class type --- except for :ref:`label <t_label>` 3411and :ref:`metadata <t_metadata>` types. 3412 3413:Syntax: 3414 3415:: 3416 3417 <returntype> (<parameter list>) 3418 3419...where '``<parameter list>``' is a comma-separated list of type 3420specifiers. Optionally, the parameter list may include a type ``...``, which 3421indicates that the function takes a variable number of arguments. Variable 3422argument functions can access their arguments with the :ref:`variable argument 3423handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type 3424except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`. 3425 3426:Examples: 3427 3428+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3429| ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` | 3430+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3431| ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. | 3432+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3433| ``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. | 3434+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3435| ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values | 3436+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3437 3438.. _t_firstclass: 3439 3440First Class Types 3441----------------- 3442 3443The :ref:`first class <t_firstclass>` types are perhaps the most important. 3444Values of these types are the only ones which can be produced by 3445instructions. 3446 3447.. _t_single_value: 3448 3449Single Value Types 3450^^^^^^^^^^^^^^^^^^ 3451 3452These are the types that are valid in registers from CodeGen's perspective. 3453 3454.. _t_integer: 3455 3456Integer Type 3457"""""""""""" 3458 3459:Overview: 3460 3461The integer type is a very simple type that simply specifies an 3462arbitrary bit width for the integer type desired. Any bit width from 1 3463bit to 2\ :sup:`23`\ (about 8 million) can be specified. 3464 3465:Syntax: 3466 3467:: 3468 3469 iN 3470 3471The number of bits the integer will occupy is specified by the ``N`` 3472value. 3473 3474Examples: 3475********* 3476 3477+----------------+------------------------------------------------+ 3478| ``i1`` | a single-bit integer. | 3479+----------------+------------------------------------------------+ 3480| ``i32`` | a 32-bit integer. | 3481+----------------+------------------------------------------------+ 3482| ``i1942652`` | a really big integer of over 1 million bits. | 3483+----------------+------------------------------------------------+ 3484 3485.. _t_floating: 3486 3487Floating-Point Types 3488"""""""""""""""""""" 3489 3490.. list-table:: 3491 :header-rows: 1 3492 3493 * - Type 3494 - Description 3495 3496 * - ``half`` 3497 - 16-bit floating-point value 3498 3499 * - ``bfloat`` 3500 - 16-bit "brain" floating-point value (7-bit significand). Provides the 3501 same number of exponent bits as ``float``, so that it matches its dynamic 3502 range, but with greatly reduced precision. Used in Intel's AVX-512 BF16 3503 extensions and Arm's ARMv8.6-A extensions, among others. 3504 3505 * - ``float`` 3506 - 32-bit floating-point value 3507 3508 * - ``double`` 3509 - 64-bit floating-point value 3510 3511 * - ``fp128`` 3512 - 128-bit floating-point value (113-bit significand) 3513 3514 * - ``x86_fp80`` 3515 - 80-bit floating-point value (X87) 3516 3517 * - ``ppc_fp128`` 3518 - 128-bit floating-point value (two 64-bits) 3519 3520The binary format of half, float, double, and fp128 correspond to the 3521IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128 3522respectively. 3523 3524X86_amx Type 3525"""""""""""" 3526 3527:Overview: 3528 3529The x86_amx type represents a value held in an AMX tile register on an x86 3530machine. The operations allowed on it are quite limited. Only few intrinsics 3531are allowed: stride load and store, zero and dot product. No instruction is 3532allowed for this type. There are no arguments, arrays, pointers, vectors 3533or constants of this type. 3534 3535:Syntax: 3536 3537:: 3538 3539 x86_amx 3540 3541 3542X86_mmx Type 3543"""""""""""" 3544 3545:Overview: 3546 3547The x86_mmx type represents a value held in an MMX register on an x86 3548machine. The operations allowed on it are quite limited: parameters and 3549return values, load and store, and bitcast. User-specified MMX 3550instructions are represented as intrinsic or asm calls with arguments 3551and/or results of this type. There are no arrays, vectors or constants 3552of this type. 3553 3554:Syntax: 3555 3556:: 3557 3558 x86_mmx 3559 3560 3561.. _t_pointer: 3562 3563Pointer Type 3564"""""""""""" 3565 3566:Overview: 3567 3568The pointer type is used to specify memory locations. Pointers are 3569commonly used to reference objects in memory. 3570 3571Pointer types may have an optional address space attribute defining the 3572numbered address space where the pointed-to object resides. The default 3573address space is number zero. The semantics of non-zero address spaces 3574are target-specific. 3575 3576Note that LLVM does not permit pointers to void (``void*``) nor does it 3577permit pointers to labels (``label*``). Use ``i8*`` instead. 3578 3579LLVM is in the process of transitioning to 3580`opaque pointers <OpaquePointers.html#opaque-pointers>`_. 3581Opaque pointers do not have a pointee type. Rather, instructions 3582interacting through pointers specify the type of the underlying memory 3583they are interacting with. Opaque pointers are still in the process of 3584being worked on and are not complete. 3585 3586:Syntax: 3587 3588:: 3589 3590 <type> * 3591 ptr 3592 3593:Examples: 3594 3595+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3596| ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. | 3597+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3598| ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. | 3599+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3600| ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space 5. | 3601+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3602| ``ptr`` | An opaque pointer type to a value that resides in address space 0. | 3603+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3604| ``ptr addrspace(5)`` | An opaque pointer type to a value that resides in address space 5. | 3605+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3606 3607.. _t_vector: 3608 3609Vector Type 3610""""""""""" 3611 3612:Overview: 3613 3614A vector type is a simple derived type that represents a vector of 3615elements. Vector types are used when multiple primitive data are 3616operated in parallel using a single instruction (SIMD). A vector type 3617requires a size (number of elements), an underlying primitive data type, 3618and a scalable property to represent vectors where the exact hardware 3619vector length is unknown at compile time. Vector types are considered 3620:ref:`first class <t_firstclass>`. 3621 3622:Memory Layout: 3623 3624In general vector elements are laid out in memory in the same way as 3625:ref:`array types <t_array>`. Such an analogy works fine as long as the vector 3626elements are byte sized. However, when the elements of the vector aren't byte 3627sized it gets a bit more complicated. One way to describe the layout is by 3628describing what happens when a vector such as <N x iM> is bitcasted to an 3629integer type with N*M bits, and then following the rules for storing such an 3630integer to memory. 3631 3632A bitcast from a vector type to a scalar integer type will see the elements 3633being packed together (without padding). The order in which elements are 3634inserted in the integer depends on endianess. For little endian element zero 3635is put in the least significant bits of the integer, and for big endian 3636element zero is put in the most significant bits. 3637 3638Using a vector such as ``<i4 1, i4 2, i4 3, i4 5>`` as an example, together 3639with the analogy that we can replace a vector store by a bitcast followed by 3640an integer store, we get this for big endian: 3641 3642.. code-block:: llvm 3643 3644 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16 3645 3646 ; Bitcasting from a vector to an integral type can be seen as 3647 ; concatenating the values: 3648 ; %val now has the hexadecimal value 0x1235. 3649 3650 store i16 %val, i16* %ptr 3651 3652 ; In memory the content will be (8-bit addressing): 3653 ; 3654 ; [%ptr + 0]: 00010010 (0x12) 3655 ; [%ptr + 1]: 00110101 (0x35) 3656 3657The same example for little endian: 3658 3659.. code-block:: llvm 3660 3661 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16 3662 3663 ; Bitcasting from a vector to an integral type can be seen as 3664 ; concatenating the values: 3665 ; %val now has the hexadecimal value 0x5321. 3666 3667 store i16 %val, i16* %ptr 3668 3669 ; In memory the content will be (8-bit addressing): 3670 ; 3671 ; [%ptr + 0]: 01010011 (0x53) 3672 ; [%ptr + 1]: 00100001 (0x21) 3673 3674When ``<N*M>`` isn't evenly divisible by the byte size the exact memory layout 3675is unspecified (just like it is for an integral type of the same size). This 3676is because different targets could put the padding at different positions when 3677the type size is smaller than the type's store size. 3678 3679:Syntax: 3680 3681:: 3682 3683 < <# elements> x <elementtype> > ; Fixed-length vector 3684 < vscale x <# elements> x <elementtype> > ; Scalable vector 3685 3686The number of elements is a constant integer value larger than 0; 3687elementtype may be any integer, floating-point or pointer type. Vectors 3688of size zero are not allowed. For scalable vectors, the total number of 3689elements is a constant multiple (called vscale) of the specified number 3690of elements; vscale is a positive integer that is unknown at compile time 3691and the same hardware-dependent constant for all scalable vectors at run 3692time. The size of a specific scalable vector type is thus constant within 3693IR, even if the exact size in bytes cannot be determined until run time. 3694 3695:Examples: 3696 3697+------------------------+----------------------------------------------------+ 3698| ``<4 x i32>`` | Vector of 4 32-bit integer values. | 3699+------------------------+----------------------------------------------------+ 3700| ``<8 x float>`` | Vector of 8 32-bit floating-point values. | 3701+------------------------+----------------------------------------------------+ 3702| ``<2 x i64>`` | Vector of 2 64-bit integer values. | 3703+------------------------+----------------------------------------------------+ 3704| ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. | 3705+------------------------+----------------------------------------------------+ 3706| ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. | 3707+------------------------+----------------------------------------------------+ 3708 3709.. _t_label: 3710 3711Label Type 3712^^^^^^^^^^ 3713 3714:Overview: 3715 3716The label type represents code labels. 3717 3718:Syntax: 3719 3720:: 3721 3722 label 3723 3724.. _t_token: 3725 3726Token Type 3727^^^^^^^^^^ 3728 3729:Overview: 3730 3731The token type is used when a value is associated with an instruction 3732but all uses of the value must not attempt to introspect or obscure it. 3733As such, it is not appropriate to have a :ref:`phi <i_phi>` or 3734:ref:`select <i_select>` of type token. 3735 3736:Syntax: 3737 3738:: 3739 3740 token 3741 3742 3743 3744.. _t_metadata: 3745 3746Metadata Type 3747^^^^^^^^^^^^^ 3748 3749:Overview: 3750 3751The metadata type represents embedded metadata. No derived types may be 3752created from metadata except for :ref:`function <t_function>` arguments. 3753 3754:Syntax: 3755 3756:: 3757 3758 metadata 3759 3760.. _t_aggregate: 3761 3762Aggregate Types 3763^^^^^^^^^^^^^^^ 3764 3765Aggregate Types are a subset of derived types that can contain multiple 3766member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are 3767aggregate types. :ref:`Vectors <t_vector>` are not considered to be 3768aggregate types. 3769 3770.. _t_array: 3771 3772Array Type 3773"""""""""" 3774 3775:Overview: 3776 3777The array type is a very simple derived type that arranges elements 3778sequentially in memory. The array type requires a size (number of 3779elements) and an underlying data type. 3780 3781:Syntax: 3782 3783:: 3784 3785 [<# elements> x <elementtype>] 3786 3787The number of elements is a constant integer value; ``elementtype`` may 3788be any type with a size. 3789 3790:Examples: 3791 3792+------------------+--------------------------------------+ 3793| ``[40 x i32]`` | Array of 40 32-bit integer values. | 3794+------------------+--------------------------------------+ 3795| ``[41 x i32]`` | Array of 41 32-bit integer values. | 3796+------------------+--------------------------------------+ 3797| ``[4 x i8]`` | Array of 4 8-bit integer values. | 3798+------------------+--------------------------------------+ 3799 3800Here are some examples of multidimensional arrays: 3801 3802+-----------------------------+----------------------------------------------------------+ 3803| ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. | 3804+-----------------------------+----------------------------------------------------------+ 3805| ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. | 3806+-----------------------------+----------------------------------------------------------+ 3807| ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. | 3808+-----------------------------+----------------------------------------------------------+ 3809 3810There is no restriction on indexing beyond the end of the array implied 3811by a static type (though there are restrictions on indexing beyond the 3812bounds of an allocated object in some cases). This means that 3813single-dimension 'variable sized array' addressing can be implemented in 3814LLVM with a zero length array type. An implementation of 'pascal style 3815arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for 3816example. 3817 3818.. _t_struct: 3819 3820Structure Type 3821"""""""""""""" 3822 3823:Overview: 3824 3825The structure type is used to represent a collection of data members 3826together in memory. The elements of a structure may be any type that has 3827a size. 3828 3829Structures in memory are accessed using '``load``' and '``store``' by 3830getting a pointer to a field with the '``getelementptr``' instruction. 3831Structures in registers are accessed using the '``extractvalue``' and 3832'``insertvalue``' instructions. 3833 3834Structures may optionally be "packed" structures, which indicate that 3835the alignment of the struct is one byte, and that there is no padding 3836between the elements. In non-packed structs, padding between field types 3837is inserted as defined by the DataLayout string in the module, which is 3838required to match what the underlying code generator expects. 3839 3840Structures can either be "literal" or "identified". A literal structure 3841is defined inline with other types (e.g. ``{i32, i32}*``) whereas 3842identified types are always defined at the top level with a name. 3843Literal types are uniqued by their contents and can never be recursive 3844or opaque since there is no way to write one. Identified types can be 3845recursive, can be opaqued, and are never uniqued. 3846 3847:Syntax: 3848 3849:: 3850 3851 %T1 = type { <type list> } ; Identified normal struct type 3852 %T2 = type <{ <type list> }> ; Identified packed struct type 3853 3854:Examples: 3855 3856+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3857| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values | 3858+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3859| ``{ 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``. | 3860+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3861| ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. | 3862+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3863 3864.. _t_opaque: 3865 3866Opaque Structure Types 3867"""""""""""""""""""""" 3868 3869:Overview: 3870 3871Opaque structure types are used to represent structure types that 3872do not have a body specified. This corresponds (for example) to the C 3873notion of a forward declared structure. They can be named (``%X``) or 3874unnamed (``%52``). 3875 3876:Syntax: 3877 3878:: 3879 3880 %X = type opaque 3881 %52 = type opaque 3882 3883:Examples: 3884 3885+--------------+-------------------+ 3886| ``opaque`` | An opaque type. | 3887+--------------+-------------------+ 3888 3889.. _constants: 3890 3891Constants 3892========= 3893 3894LLVM has several different basic types of constants. This section 3895describes them all and their syntax. 3896 3897Simple Constants 3898---------------- 3899 3900**Boolean constants** 3901 The two strings '``true``' and '``false``' are both valid constants 3902 of the ``i1`` type. 3903**Integer constants** 3904 Standard integers (such as '4') are constants of the 3905 :ref:`integer <t_integer>` type. Negative numbers may be used with 3906 integer types. 3907**Floating-point constants** 3908 Floating-point constants use standard decimal notation (e.g. 3909 123.421), exponential notation (e.g. 1.23421e+2), or a more precise 3910 hexadecimal notation (see below). The assembler requires the exact 3911 decimal value of a floating-point constant. For example, the 3912 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating 3913 decimal in binary. Floating-point constants must have a 3914 :ref:`floating-point <t_floating>` type. 3915**Null pointer constants** 3916 The identifier '``null``' is recognized as a null pointer constant 3917 and must be of :ref:`pointer type <t_pointer>`. 3918**Token constants** 3919 The identifier '``none``' is recognized as an empty token constant 3920 and must be of :ref:`token type <t_token>`. 3921 3922The one non-intuitive notation for constants is the hexadecimal form of 3923floating-point constants. For example, the form 3924'``double 0x432ff973cafa8000``' is equivalent to (but harder to read 3925than) '``double 4.5e+15``'. The only time hexadecimal floating-point 3926constants are required (and the only time that they are generated by the 3927disassembler) is when a floating-point constant must be emitted but it 3928cannot be represented as a decimal floating-point number in a reasonable 3929number of digits. For example, NaN's, infinities, and other special 3930values are represented in their IEEE hexadecimal format so that assembly 3931and disassembly do not cause any bits to change in the constants. 3932 3933When using the hexadecimal form, constants of types bfloat, half, float, and 3934double are represented using the 16-digit form shown above (which matches the 3935IEEE754 representation for double); bfloat, half and float values must, however, 3936be exactly representable as bfloat, IEEE 754 half, and IEEE 754 single 3937precision respectively. Hexadecimal format is always used for long double, and 3938there are three forms of long double. The 80-bit format used by x86 is 3939represented as ``0xK`` followed by 20 hexadecimal digits. The 128-bit format 3940used by PowerPC (two adjacent doubles) is represented by ``0xM`` followed by 32 3941hexadecimal digits. The IEEE 128-bit format is represented by ``0xL`` followed 3942by 32 hexadecimal digits. Long doubles will only work if they match the long 3943double format on your target. The IEEE 16-bit format (half precision) is 3944represented by ``0xH`` followed by 4 hexadecimal digits. The bfloat 16-bit 3945format is represented by ``0xR`` followed by 4 hexadecimal digits. All 3946hexadecimal formats are big-endian (sign bit at the left). 3947 3948There are no constants of type x86_mmx and x86_amx. 3949 3950.. _complexconstants: 3951 3952Complex Constants 3953----------------- 3954 3955Complex constants are a (potentially recursive) combination of simple 3956constants and smaller complex constants. 3957 3958**Structure constants** 3959 Structure constants are represented with notation similar to 3960 structure type definitions (a comma separated list of elements, 3961 surrounded by braces (``{}``)). For example: 3962 "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as 3963 "``@G = external global i32``". Structure constants must have 3964 :ref:`structure type <t_struct>`, and the number and types of elements 3965 must match those specified by the type. 3966**Array constants** 3967 Array constants are represented with notation similar to array type 3968 definitions (a comma separated list of elements, surrounded by 3969 square brackets (``[]``)). For example: 3970 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have 3971 :ref:`array type <t_array>`, and the number and types of elements must 3972 match those specified by the type. As a special case, character array 3973 constants may also be represented as a double-quoted string using the ``c`` 3974 prefix. For example: "``c"Hello World\0A\00"``". 3975**Vector constants** 3976 Vector constants are represented with notation similar to vector 3977 type definitions (a comma separated list of elements, surrounded by 3978 less-than/greater-than's (``<>``)). For example: 3979 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants 3980 must have :ref:`vector type <t_vector>`, and the number and types of 3981 elements must match those specified by the type. 3982**Zero initialization** 3983 The string '``zeroinitializer``' can be used to zero initialize a 3984 value to zero of *any* type, including scalar and 3985 :ref:`aggregate <t_aggregate>` types. This is often used to avoid 3986 having to print large zero initializers (e.g. for large arrays) and 3987 is always exactly equivalent to using explicit zero initializers. 3988**Metadata node** 3989 A metadata node is a constant tuple without types. For example: 3990 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values, 3991 for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``". 3992 Unlike other typed constants that are meant to be interpreted as part of 3993 the instruction stream, metadata is a place to attach additional 3994 information such as debug info. 3995 3996Global Variable and Function Addresses 3997-------------------------------------- 3998 3999The addresses of :ref:`global variables <globalvars>` and 4000:ref:`functions <functionstructure>` are always implicitly valid 4001(link-time) constants. These constants are explicitly referenced when 4002the :ref:`identifier for the global <identifiers>` is used and always have 4003:ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM 4004file: 4005 4006.. code-block:: llvm 4007 4008 @X = global i32 17 4009 @Y = global i32 42 4010 @Z = global [2 x i32*] [ i32* @X, i32* @Y ] 4011 4012.. _undefvalues: 4013 4014Undefined Values 4015---------------- 4016 4017The string '``undef``' can be used anywhere a constant is expected, and 4018indicates that the user of the value may receive an unspecified 4019bit-pattern. Undefined values may be of any type (other than '``label``' 4020or '``void``') and be used anywhere a constant is permitted. 4021 4022.. note:: 4023 4024 A '``poison``' value (decribed in the next section) should be used instead of 4025 '``undef``' whenever possible. Poison values are stronger than undef, and 4026 enable more optimizations. Just the existence of '``undef``' blocks certain 4027 optimizations (see the examples below). 4028 4029Undefined values are useful because they indicate to the compiler that 4030the program is well defined no matter what value is used. This gives the 4031compiler more freedom to optimize. Here are some examples of 4032(potentially surprising) transformations that are valid (in pseudo IR): 4033 4034.. code-block:: llvm 4035 4036 %A = add %X, undef 4037 %B = sub %X, undef 4038 %C = xor %X, undef 4039 Safe: 4040 %A = undef 4041 %B = undef 4042 %C = undef 4043 4044This is safe because all of the output bits are affected by the undef 4045bits. Any output bit can have a zero or one depending on the input bits. 4046 4047.. code-block:: llvm 4048 4049 %A = or %X, undef 4050 %B = and %X, undef 4051 Safe: 4052 %A = -1 4053 %B = 0 4054 Safe: 4055 %A = %X ;; By choosing undef as 0 4056 %B = %X ;; By choosing undef as -1 4057 Unsafe: 4058 %A = undef 4059 %B = undef 4060 4061These logical operations have bits that are not always affected by the 4062input. For example, if ``%X`` has a zero bit, then the output of the 4063'``and``' operation will always be a zero for that bit, no matter what 4064the corresponding bit from the '``undef``' is. As such, it is unsafe to 4065optimize or assume that the result of the '``and``' is '``undef``'. 4066However, it is safe to assume that all bits of the '``undef``' could be 40670, and optimize the '``and``' to 0. Likewise, it is safe to assume that 4068all the bits of the '``undef``' operand to the '``or``' could be set, 4069allowing the '``or``' to be folded to -1. 4070 4071.. code-block:: llvm 4072 4073 %A = select undef, %X, %Y 4074 %B = select undef, 42, %Y 4075 %C = select %X, %Y, undef 4076 Safe: 4077 %A = %X (or %Y) 4078 %B = 42 (or %Y) 4079 %C = %Y (if %Y is provably not poison; unsafe otherwise) 4080 Unsafe: 4081 %A = undef 4082 %B = undef 4083 %C = undef 4084 4085This set of examples shows that undefined '``select``' (and conditional 4086branch) conditions can go *either way*, but they have to come from one 4087of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were 4088both known to have a clear low bit, then ``%A`` would have to have a 4089cleared low bit. However, in the ``%C`` example, the optimizer is 4090allowed to assume that the '``undef``' operand could be the same as 4091``%Y`` if ``%Y`` is provably not '``poison``', allowing the whole '``select``' 4092to be eliminated. This is because '``poison``' is stronger than '``undef``'. 4093 4094.. code-block:: llvm 4095 4096 %A = xor undef, undef 4097 4098 %B = undef 4099 %C = xor %B, %B 4100 4101 %D = undef 4102 %E = icmp slt %D, 4 4103 %F = icmp gte %D, 4 4104 4105 Safe: 4106 %A = undef 4107 %B = undef 4108 %C = undef 4109 %D = undef 4110 %E = undef 4111 %F = undef 4112 4113This example points out that two '``undef``' operands are not 4114necessarily the same. This can be surprising to people (and also matches 4115C semantics) where they assume that "``X^X``" is always zero, even if 4116``X`` is undefined. This isn't true for a number of reasons, but the 4117short answer is that an '``undef``' "variable" can arbitrarily change 4118its value over its "live range". This is true because the variable 4119doesn't actually *have a live range*. Instead, the value is logically 4120read from arbitrary registers that happen to be around when needed, so 4121the value is not necessarily consistent over time. In fact, ``%A`` and 4122``%C`` need to have the same semantics or the core LLVM "replace all 4123uses with" concept would not hold. 4124 4125To ensure all uses of a given register observe the same value (even if 4126'``undef``'), the :ref:`freeze instruction <i_freeze>` can be used. 4127 4128.. code-block:: llvm 4129 4130 %A = sdiv undef, %X 4131 %B = sdiv %X, undef 4132 Safe: 4133 %A = 0 4134 b: unreachable 4135 4136These examples show the crucial difference between an *undefined value* 4137and *undefined behavior*. An undefined value (like '``undef``') is 4138allowed to have an arbitrary bit-pattern. This means that the ``%A`` 4139operation can be constant folded to '``0``', because the '``undef``' 4140could be zero, and zero divided by any value is zero. 4141However, in the second example, we can make a more aggressive 4142assumption: because the ``undef`` is allowed to be an arbitrary value, 4143we are allowed to assume that it could be zero. Since a divide by zero 4144has *undefined behavior*, we are allowed to assume that the operation 4145does not execute at all. This allows us to delete the divide and all 4146code after it. Because the undefined operation "can't happen", the 4147optimizer can assume that it occurs in dead code. 4148 4149.. code-block:: text 4150 4151 a: store undef -> %X 4152 b: store %X -> undef 4153 Safe: 4154 a: <deleted> (if the stored value in %X is provably not poison) 4155 b: unreachable 4156 4157A store *of* an undefined value can be assumed to not have any effect; 4158we can assume that the value is overwritten with bits that happen to 4159match what was already there. This argument is only valid if the stored value 4160is provably not ``poison``. However, a store *to* an undefined 4161location could clobber arbitrary memory, therefore, it has undefined 4162behavior. 4163 4164Branching on an undefined value is undefined behavior. 4165This explains optimizations that depend on branch conditions to construct 4166predicates, such as Correlated Value Propagation and Global Value Numbering. 4167In case of switch instruction, the branch condition should be frozen, otherwise 4168it is undefined behavior. 4169 4170.. code-block:: llvm 4171 4172 Unsafe: 4173 br undef, BB1, BB2 ; UB 4174 4175 %X = and i32 undef, 255 4176 switch %X, label %ret [ .. ] ; UB 4177 4178 store undef, i8* %ptr 4179 %X = load i8* %ptr ; %X is undef 4180 switch i8 %X, label %ret [ .. ] ; UB 4181 4182 Safe: 4183 %X = or i8 undef, 255 ; always 255 4184 switch i8 %X, label %ret [ .. ] ; Well-defined 4185 4186 %X = freeze i1 undef 4187 br %X, BB1, BB2 ; Well-defined (non-deterministic jump) 4188 4189 4190 4191.. _poisonvalues: 4192 4193Poison Values 4194------------- 4195 4196A poison value is a result of an erroneous operation. 4197In order to facilitate speculative execution, many instructions do not 4198invoke immediate undefined behavior when provided with illegal operands, 4199and return a poison value instead. 4200The string '``poison``' can be used anywhere a constant is expected, and 4201operations such as :ref:`add <i_add>` with the ``nsw`` flag can produce 4202a poison value. 4203 4204Most instructions return '``poison``' when one of their arguments is 4205'``poison``'. A notable exception is the :ref:`select instruction <i_select>`. 4206Propagation of poison can be stopped with the 4207:ref:`freeze instruction <i_freeze>`. 4208 4209It is correct to replace a poison value with an 4210:ref:`undef value <undefvalues>` or any value of the type. 4211 4212This means that immediate undefined behavior occurs if a poison value is 4213used as an instruction operand that has any values that trigger undefined 4214behavior. Notably this includes (but is not limited to): 4215 4216- The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or 4217 any other pointer dereferencing instruction (independent of address 4218 space). 4219- The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem`` 4220 instruction. 4221- The condition operand of a :ref:`br <i_br>` instruction. 4222- The callee operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 4223 instruction. 4224- The parameter operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 4225 instruction, when the function or invoking call site has a ``noundef`` 4226 attribute in the corresponding position. 4227- The operand of a :ref:`ret <i_ret>` instruction if the function or invoking 4228 call site has a `noundef` attribute in the return value position. 4229 4230Here are some examples: 4231 4232.. code-block:: llvm 4233 4234 entry: 4235 %poison = sub nuw i32 0, 1 ; Results in a poison value. 4236 %poison2 = sub i32 poison, 1 ; Also results in a poison value. 4237 %still_poison = and i32 %poison, 0 ; 0, but also poison. 4238 %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison 4239 store i32 0, i32* %poison_yet_again ; Undefined behavior due to 4240 ; store to poison. 4241 4242 store i32 %poison, i32* @g ; Poison value stored to memory. 4243 %poison3 = load i32, i32* @g ; Poison value loaded back from memory. 4244 4245 %narrowaddr = bitcast i32* @g to i16* 4246 %wideaddr = bitcast i32* @g to i64* 4247 %poison4 = load i16, i16* %narrowaddr ; Returns a poison value. 4248 %poison5 = load i64, i64* %wideaddr ; Returns a poison value. 4249 4250 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value. 4251 br i1 %cmp, label %end, label %end ; undefined behavior 4252 4253 end: 4254 4255.. _welldefinedvalues: 4256 4257Well-Defined Values 4258------------------- 4259 4260Given a program execution, a value is *well defined* if the value does not 4261have an undef bit and is not poison in the execution. 4262An aggregate value or vector is well defined if its elements are well defined. 4263The padding of an aggregate isn't considered, since it isn't visible 4264without storing it into memory and loading it with a different type. 4265 4266A constant of a :ref:`single value <t_single_value>`, non-vector type is well 4267defined if it is neither '``undef``' constant nor '``poison``' constant. 4268The result of :ref:`freeze instruction <i_freeze>` is well defined regardless 4269of its operand. 4270 4271.. _blockaddress: 4272 4273Addresses of Basic Blocks 4274------------------------- 4275 4276``blockaddress(@function, %block)`` 4277 4278The '``blockaddress``' constant computes the address of the specified 4279basic block in the specified function. 4280 4281It always has an ``i8 addrspace(P)*`` type, where ``P`` is the address space 4282of the function containing ``%block`` (usually ``addrspace(0)``). 4283 4284Taking the address of the entry block is illegal. 4285 4286This value only has defined behavior when used as an operand to the 4287':ref:`indirectbr <i_indirectbr>`' or ':ref:`callbr <i_callbr>`'instruction, or 4288for comparisons against null. Pointer equality tests between labels addresses 4289results in undefined behavior --- though, again, comparison against null is ok, 4290and no label is equal to the null pointer. This may be passed around as an 4291opaque pointer sized value as long as the bits are not inspected. This 4292allows ``ptrtoint`` and arithmetic to be performed on these values so 4293long as the original value is reconstituted before the ``indirectbr`` or 4294``callbr`` instruction. 4295 4296Finally, some targets may provide defined semantics when using the value 4297as the operand to an inline assembly, but that is target specific. 4298 4299.. _dso_local_equivalent: 4300 4301DSO Local Equivalent 4302-------------------- 4303 4304``dso_local_equivalent @func`` 4305 4306A '``dso_local_equivalent``' constant represents a function which is 4307functionally equivalent to a given function, but is always defined in the 4308current linkage unit. The resulting pointer has the same type as the underlying 4309function. The resulting pointer is permitted, but not required, to be different 4310from a pointer to the function, and it may have different values in different 4311translation units. 4312 4313The target function may not have ``extern_weak`` linkage. 4314 4315``dso_local_equivalent`` can be implemented as such: 4316 4317- If the function has local linkage, hidden visibility, or is 4318 ``dso_local``, ``dso_local_equivalent`` can be implemented as simply a pointer 4319 to the function. 4320- ``dso_local_equivalent`` can be implemented with a stub that tail-calls the 4321 function. Many targets support relocations that resolve at link time to either 4322 a function or a stub for it, depending on if the function is defined within the 4323 linkage unit; LLVM will use this when available. (This is commonly called a 4324 "PLT stub".) On other targets, the stub may need to be emitted explicitly. 4325 4326This can be used wherever a ``dso_local`` instance of a function is needed without 4327needing to explicitly make the original function ``dso_local``. An instance where 4328this can be used is for static offset calculations between a function and some other 4329``dso_local`` symbol. This is especially useful for the Relative VTables C++ ABI, 4330where dynamic relocations for function pointers in VTables can be replaced with 4331static relocations for offsets between the VTable and virtual functions which 4332may not be ``dso_local``. 4333 4334This is currently only supported for ELF binary formats. 4335 4336.. _no_cfi: 4337 4338No CFI 4339------ 4340 4341``no_cfi @func`` 4342 4343With `Control-Flow Integrity (CFI) 4344<https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, a '``no_cfi``' 4345constant represents a function reference that does not get replaced with a 4346reference to the CFI jump table in the ``LowerTypeTests`` pass. These constants 4347may be useful in low-level programs, such as operating system kernels, which 4348need to refer to the actual function body. 4349 4350.. _constantexprs: 4351 4352Constant Expressions 4353-------------------- 4354 4355Constant expressions are used to allow expressions involving other 4356constants to be used as constants. Constant expressions may be of any 4357:ref:`first class <t_firstclass>` type and may involve any LLVM operation 4358that does not have side effects (e.g. load and call are not supported). 4359The following is the syntax for constant expressions: 4360 4361``trunc (CST to TYPE)`` 4362 Perform the :ref:`trunc operation <i_trunc>` on constants. 4363``zext (CST to TYPE)`` 4364 Perform the :ref:`zext operation <i_zext>` on constants. 4365``sext (CST to TYPE)`` 4366 Perform the :ref:`sext operation <i_sext>` on constants. 4367``fptrunc (CST to TYPE)`` 4368 Truncate a floating-point constant to another floating-point type. 4369 The size of CST must be larger than the size of TYPE. Both types 4370 must be floating-point. 4371``fpext (CST to TYPE)`` 4372 Floating-point extend a constant to another type. The size of CST 4373 must be smaller or equal to the size of TYPE. Both types must be 4374 floating-point. 4375``fptoui (CST to TYPE)`` 4376 Convert a floating-point constant to the corresponding unsigned 4377 integer constant. TYPE must be a scalar or vector integer type. CST 4378 must be of scalar or vector floating-point type. Both CST and TYPE 4379 must be scalars, or vectors of the same number of elements. If the 4380 value won't fit in the integer type, the result is a 4381 :ref:`poison value <poisonvalues>`. 4382``fptosi (CST to TYPE)`` 4383 Convert a floating-point constant to the corresponding signed 4384 integer constant. TYPE must be a scalar or vector integer type. CST 4385 must be of scalar or vector floating-point type. Both CST and TYPE 4386 must be scalars, or vectors of the same number of elements. If the 4387 value won't fit in the integer type, the result is a 4388 :ref:`poison value <poisonvalues>`. 4389``uitofp (CST to TYPE)`` 4390 Convert an unsigned integer constant to the corresponding 4391 floating-point constant. TYPE must be a scalar or vector floating-point 4392 type. CST must be of scalar or vector integer type. Both CST and TYPE must 4393 be scalars, or vectors of the same number of elements. 4394``sitofp (CST to TYPE)`` 4395 Convert a signed integer constant to the corresponding floating-point 4396 constant. TYPE must be a scalar or vector floating-point type. 4397 CST must be of scalar or vector integer type. Both CST and TYPE must 4398 be scalars, or vectors of the same number of elements. 4399``ptrtoint (CST to TYPE)`` 4400 Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants. 4401``inttoptr (CST to TYPE)`` 4402 Perform the :ref:`inttoptr operation <i_inttoptr>` on constants. 4403 This one is *really* dangerous! 4404``bitcast (CST to TYPE)`` 4405 Convert a constant, CST, to another TYPE. 4406 The constraints of the operands are the same as those for the 4407 :ref:`bitcast instruction <i_bitcast>`. 4408``addrspacecast (CST to TYPE)`` 4409 Convert a constant pointer or constant vector of pointer, CST, to another 4410 TYPE in a different address space. The constraints of the operands are the 4411 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`. 4412``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)`` 4413 Perform the :ref:`getelementptr operation <i_getelementptr>` on 4414 constants. As with the :ref:`getelementptr <i_getelementptr>` 4415 instruction, the index list may have one or more indexes, which are 4416 required to make sense for the type of "pointer to TY". 4417``select (COND, VAL1, VAL2)`` 4418 Perform the :ref:`select operation <i_select>` on constants. 4419``icmp COND (VAL1, VAL2)`` 4420 Perform the :ref:`icmp operation <i_icmp>` on constants. 4421``fcmp COND (VAL1, VAL2)`` 4422 Perform the :ref:`fcmp operation <i_fcmp>` on constants. 4423``extractelement (VAL, IDX)`` 4424 Perform the :ref:`extractelement operation <i_extractelement>` on 4425 constants. 4426``insertelement (VAL, ELT, IDX)`` 4427 Perform the :ref:`insertelement operation <i_insertelement>` on 4428 constants. 4429``shufflevector (VEC1, VEC2, IDXMASK)`` 4430 Perform the :ref:`shufflevector operation <i_shufflevector>` on 4431 constants. 4432``extractvalue (VAL, IDX0, IDX1, ...)`` 4433 Perform the :ref:`extractvalue operation <i_extractvalue>` on 4434 constants. The index list is interpreted in a similar manner as 4435 indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At 4436 least one index value must be specified. 4437``insertvalue (VAL, ELT, IDX0, IDX1, ...)`` 4438 Perform the :ref:`insertvalue operation <i_insertvalue>` on constants. 4439 The index list is interpreted in a similar manner as indices in a 4440 ':ref:`getelementptr <i_getelementptr>`' operation. At least one index 4441 value must be specified. 4442``OPCODE (LHS, RHS)`` 4443 Perform the specified operation of the LHS and RHS constants. OPCODE 4444 may be any of the :ref:`binary <binaryops>` or :ref:`bitwise 4445 binary <bitwiseops>` operations. The constraints on operands are 4446 the same as those for the corresponding instruction (e.g. no bitwise 4447 operations on floating-point values are allowed). 4448 4449Other Values 4450============ 4451 4452.. _inlineasmexprs: 4453 4454Inline Assembler Expressions 4455---------------------------- 4456 4457LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level 4458Inline Assembly <moduleasm>`) through the use of a special value. This value 4459represents the inline assembler as a template string (containing the 4460instructions to emit), a list of operand constraints (stored as a string), a 4461flag that indicates whether or not the inline asm expression has side effects, 4462and a flag indicating whether the function containing the asm needs to align its 4463stack conservatively. 4464 4465The template string supports argument substitution of the operands using "``$``" 4466followed by a number, to indicate substitution of the given register/memory 4467location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also 4468be used, where ``MODIFIER`` is a target-specific annotation for how to print the 4469operand (See :ref:`inline-asm-modifiers`). 4470 4471A literal "``$``" may be included by using "``$$``" in the template. To include 4472other special characters into the output, the usual "``\XX``" escapes may be 4473used, just as in other strings. Note that after template substitution, the 4474resulting assembly string is parsed by LLVM's integrated assembler unless it is 4475disabled -- even when emitting a ``.s`` file -- and thus must contain assembly 4476syntax known to LLVM. 4477 4478LLVM also supports a few more substitutions useful for writing inline assembly: 4479 4480- ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob. 4481 This substitution is useful when declaring a local label. Many standard 4482 compiler optimizations, such as inlining, may duplicate an inline asm blob. 4483 Adding a blob-unique identifier ensures that the two labels will not conflict 4484 during assembly. This is used to implement `GCC's %= special format 4485 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_. 4486- ``${:comment}``: Expands to the comment character of the current target's 4487 assembly dialect. This is usually ``#``, but many targets use other strings, 4488 such as ``;``, ``//``, or ``!``. 4489- ``${:private}``: Expands to the assembler private label prefix. Labels with 4490 this prefix will not appear in the symbol table of the assembled object. 4491 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is 4492 relatively popular. 4493 4494LLVM's support for inline asm is modeled closely on the requirements of Clang's 4495GCC-compatible inline-asm support. Thus, the feature-set and the constraint and 4496modifier codes listed here are similar or identical to those in GCC's inline asm 4497support. However, to be clear, the syntax of the template and constraint strings 4498described here is *not* the same as the syntax accepted by GCC and Clang, and, 4499while most constraint letters are passed through as-is by Clang, some get 4500translated to other codes when converting from the C source to the LLVM 4501assembly. 4502 4503An example inline assembler expression is: 4504 4505.. code-block:: llvm 4506 4507 i32 (i32) asm "bswap $0", "=r,r" 4508 4509Inline assembler expressions may **only** be used as the callee operand 4510of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction. 4511Thus, typically we have: 4512 4513.. code-block:: llvm 4514 4515 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y) 4516 4517Inline asms with side effects not visible in the constraint list must be 4518marked as having side effects. This is done through the use of the 4519'``sideeffect``' keyword, like so: 4520 4521.. code-block:: llvm 4522 4523 call void asm sideeffect "eieio", ""() 4524 4525In some cases inline asms will contain code that will not work unless 4526the stack is aligned in some way, such as calls or SSE instructions on 4527x86, yet will not contain code that does that alignment within the asm. 4528The compiler should make conservative assumptions about what the asm 4529might contain and should generate its usual stack alignment code in the 4530prologue if the '``alignstack``' keyword is present: 4531 4532.. code-block:: llvm 4533 4534 call void asm alignstack "eieio", ""() 4535 4536Inline asms also support using non-standard assembly dialects. The 4537assumed dialect is ATT. When the '``inteldialect``' keyword is present, 4538the inline asm is using the Intel dialect. Currently, ATT and Intel are 4539the only supported dialects. An example is: 4540 4541.. code-block:: llvm 4542 4543 call void asm inteldialect "eieio", ""() 4544 4545In the case that the inline asm might unwind the stack, 4546the '``unwind``' keyword must be used, so that the compiler emits 4547unwinding information: 4548 4549.. code-block:: llvm 4550 4551 call void asm unwind "call func", ""() 4552 4553If the inline asm unwinds the stack and isn't marked with 4554the '``unwind``' keyword, the behavior is undefined. 4555 4556If multiple keywords appear, the '``sideeffect``' keyword must come 4557first, the '``alignstack``' keyword second, the '``inteldialect``' keyword 4558third and the '``unwind``' keyword last. 4559 4560Inline Asm Constraint String 4561^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4562 4563The constraint list is a comma-separated string, each element containing one or 4564more constraint codes. 4565 4566For each element in the constraint list an appropriate register or memory 4567operand will be chosen, and it will be made available to assembly template 4568string expansion as ``$0`` for the first constraint in the list, ``$1`` for the 4569second, etc. 4570 4571There are three different types of constraints, which are distinguished by a 4572prefix symbol in front of the constraint code: Output, Input, and Clobber. The 4573constraints must always be given in that order: outputs first, then inputs, then 4574clobbers. They cannot be intermingled. 4575 4576There are also three different categories of constraint codes: 4577 4578- Register constraint. This is either a register class, or a fixed physical 4579 register. This kind of constraint will allocate a register, and if necessary, 4580 bitcast the argument or result to the appropriate type. 4581- Memory constraint. This kind of constraint is for use with an instruction 4582 taking a memory operand. Different constraints allow for different addressing 4583 modes used by the target. 4584- Immediate value constraint. This kind of constraint is for an integer or other 4585 immediate value which can be rendered directly into an instruction. The 4586 various target-specific constraints allow the selection of a value in the 4587 proper range for the instruction you wish to use it with. 4588 4589Output constraints 4590"""""""""""""""""" 4591 4592Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This 4593indicates that the assembly will write to this operand, and the operand will 4594then be made available as a return value of the ``asm`` expression. Output 4595constraints do not consume an argument from the call instruction. (Except, see 4596below about indirect outputs). 4597 4598Normally, it is expected that no output locations are written to by the assembly 4599expression until *all* of the inputs have been read. As such, LLVM may assign 4600the same register to an output and an input. If this is not safe (e.g. if the 4601assembly contains two instructions, where the first writes to one output, and 4602the second reads an input and writes to a second output), then the "``&``" 4603modifier must be used (e.g. "``=&r``") to specify that the output is an 4604"early-clobber" output. Marking an output as "early-clobber" ensures that LLVM 4605will not use the same register for any inputs (other than an input tied to this 4606output). 4607 4608Input constraints 4609""""""""""""""""" 4610 4611Input constraints do not have a prefix -- just the constraint codes. Each input 4612constraint will consume one argument from the call instruction. It is not 4613permitted for the asm to write to any input register or memory location (unless 4614that input is tied to an output). Note also that multiple inputs may all be 4615assigned to the same register, if LLVM can determine that they necessarily all 4616contain the same value. 4617 4618Instead of providing a Constraint Code, input constraints may also "tie" 4619themselves to an output constraint, by providing an integer as the constraint 4620string. Tied inputs still consume an argument from the call instruction, and 4621take up a position in the asm template numbering as is usual -- they will simply 4622be constrained to always use the same register as the output they've been tied 4623to. For example, a constraint string of "``=r,0``" says to assign a register for 4624output, and use that register as an input as well (it being the 0'th 4625constraint). 4626 4627It is permitted to tie an input to an "early-clobber" output. In that case, no 4628*other* input may share the same register as the input tied to the early-clobber 4629(even when the other input has the same value). 4630 4631You may only tie an input to an output which has a register constraint, not a 4632memory constraint. Only a single input may be tied to an output. 4633 4634There is also an "interesting" feature which deserves a bit of explanation: if a 4635register class constraint allocates a register which is too small for the value 4636type operand provided as input, the input value will be split into multiple 4637registers, and all of them passed to the inline asm. 4638 4639However, this feature is often not as useful as you might think. 4640 4641Firstly, the registers are *not* guaranteed to be consecutive. So, on those 4642architectures that have instructions which operate on multiple consecutive 4643instructions, this is not an appropriate way to support them. (e.g. the 32-bit 4644SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The 4645hardware then loads into both the named register, and the next register. This 4646feature of inline asm would not be useful to support that.) 4647 4648A few of the targets provide a template string modifier allowing explicit access 4649to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and 4650``D``). On such an architecture, you can actually access the second allocated 4651register (yet, still, not any subsequent ones). But, in that case, you're still 4652probably better off simply splitting the value into two separate operands, for 4653clarity. (e.g. see the description of the ``A`` constraint on X86, which, 4654despite existing only for use with this feature, is not really a good idea to 4655use) 4656 4657Indirect inputs and outputs 4658""""""""""""""""""""""""""" 4659 4660Indirect output or input constraints can be specified by the "``*``" modifier 4661(which goes after the "``=``" in case of an output). This indicates that the asm 4662will write to or read from the contents of an *address* provided as an input 4663argument. (Note that in this way, indirect outputs act more like an *input* than 4664an output: just like an input, they consume an argument of the call expression, 4665rather than producing a return value. An indirect output constraint is an 4666"output" only in that the asm is expected to write to the contents of the input 4667memory location, instead of just read from it). 4668 4669This is most typically used for memory constraint, e.g. "``=*m``", to pass the 4670address of a variable as a value. 4671 4672It is also possible to use an indirect *register* constraint, but only on output 4673(e.g. "``=*r``"). This will cause LLVM to allocate a register for an output 4674value normally, and then, separately emit a store to the address provided as 4675input, after the provided inline asm. (It's not clear what value this 4676functionality provides, compared to writing the store explicitly after the asm 4677statement, and it can only produce worse code, since it bypasses many 4678optimization passes. I would recommend not using it.) 4679 4680Call arguments for indirect constraints must have pointer type and must specify 4681the :ref:`elementtype <attr_elementtype>` attribute to indicate the pointer 4682element type. 4683 4684Clobber constraints 4685""""""""""""""""""" 4686 4687A clobber constraint is indicated by a "``~``" prefix. A clobber does not 4688consume an input operand, nor generate an output. Clobbers cannot use any of the 4689general constraint code letters -- they may use only explicit register 4690constraints, e.g. "``~{eax}``". The one exception is that a clobber string of 4691"``~{memory}``" indicates that the assembly writes to arbitrary undeclared 4692memory locations -- not only the memory pointed to by a declared indirect 4693output. 4694 4695Note that clobbering named registers that are also present in output 4696constraints is not legal. 4697 4698Label constraints 4699""""""""""""""""" 4700 4701A label constraint is indicated by a "``!``" prefix and typically used in the 4702form ``"!i"``. Instead of consuming call arguments, label constraints consume 4703indirect destination labels of ``callbr`` instructions. 4704 4705Label constraints can only be used in conjunction with ``callbr`` and the 4706number of label constraints must match the number of indirect destination 4707labels in the ``callbr`` instruction. 4708 4709 4710Constraint Codes 4711"""""""""""""""" 4712After a potential prefix comes constraint code, or codes. 4713 4714A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character 4715followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``" 4716(e.g. "``{eax}``"). 4717 4718The one and two letter constraint codes are typically chosen to be the same as 4719GCC's constraint codes. 4720 4721A single constraint may include one or more than constraint code in it, leaving 4722it up to LLVM to choose which one to use. This is included mainly for 4723compatibility with the translation of GCC inline asm coming from clang. 4724 4725There are two ways to specify alternatives, and either or both may be used in an 4726inline asm constraint list: 4727 47281) Append the codes to each other, making a constraint code set. E.g. "``im``" 4729 or "``{eax}m``". This means "choose any of the options in the set". The 4730 choice of constraint is made independently for each constraint in the 4731 constraint list. 4732 47332) Use "``|``" between constraint code sets, creating alternatives. Every 4734 constraint in the constraint list must have the same number of alternative 4735 sets. With this syntax, the same alternative in *all* of the items in the 4736 constraint list will be chosen together. 4737 4738Putting those together, you might have a two operand constraint string like 4739``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then 4740operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1 4741may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m. 4742 4743However, the use of either of the alternatives features is *NOT* recommended, as 4744LLVM is not able to make an intelligent choice about which one to use. (At the 4745point it currently needs to choose, not enough information is available to do so 4746in a smart way.) Thus, it simply tries to make a choice that's most likely to 4747compile, not one that will be optimal performance. (e.g., given "``rm``", it'll 4748always choose to use memory, not registers). And, if given multiple registers, 4749or multiple register classes, it will simply choose the first one. (In fact, it 4750doesn't currently even ensure explicitly specified physical registers are 4751unique, so specifying multiple physical registers as alternatives, like 4752``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was 4753intended.) 4754 4755Supported Constraint Code List 4756"""""""""""""""""""""""""""""" 4757 4758The constraint codes are, in general, expected to behave the same way they do in 4759GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 4760inline asm code which was supported by GCC. A mismatch in behavior between LLVM 4761and GCC likely indicates a bug in LLVM. 4762 4763Some constraint codes are typically supported by all targets: 4764 4765- ``r``: A register in the target's general purpose register class. 4766- ``m``: A memory address operand. It is target-specific what addressing modes 4767 are supported, typical examples are register, or register + register offset, 4768 or register + immediate offset (of some target-specific size). 4769- ``p``: An address operand. Similar to ``m``, but used by "load address" 4770 type instructions without touching memory. 4771- ``i``: An integer constant (of target-specific width). Allows either a simple 4772 immediate, or a relocatable value. 4773- ``n``: An integer constant -- *not* including relocatable values. 4774- ``s``: An integer constant, but allowing *only* relocatable values. 4775- ``X``: Allows an operand of any kind, no constraint whatsoever. Typically 4776 useful to pass a label for an asm branch or call. 4777 4778 .. FIXME: but that surely isn't actually okay to jump out of an asm 4779 block without telling llvm about the control transfer???) 4780 4781- ``{register-name}``: Requires exactly the named physical register. 4782 4783Other constraints are target-specific: 4784 4785AArch64: 4786 4787- ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate. 4788- ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction, 4789 i.e. 0 to 4095 with optional shift by 12. 4790- ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or 4791 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12. 4792- ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a 4793 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register. 4794- ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a 4795 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register. 4796- ``M``: An immediate integer for use with the ``MOV`` assembly alias on a 4797 32-bit register. This is a superset of ``K``: in addition to the bitmask 4798 immediate, also allows immediate integers which can be loaded with a single 4799 ``MOVZ`` or ``MOVL`` instruction. 4800- ``N``: An immediate integer for use with the ``MOV`` assembly alias on a 4801 64-bit register. This is a superset of ``L``. 4802- ``Q``: Memory address operand must be in a single register (no 4803 offsets). (However, LLVM currently does this for the ``m`` constraint as 4804 well.) 4805- ``r``: A 32 or 64-bit integer register (W* or X*). 4806- ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register. 4807- ``x``: Like w, but restricted to registers 0 to 15 inclusive. 4808- ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive. 4809- ``Upl``: One of the low eight SVE predicate registers (P0 to P7) 4810- ``Upa``: Any of the SVE predicate registers (P0 to P15) 4811 4812AMDGPU: 4813 4814- ``r``: A 32 or 64-bit integer register. 4815- ``[0-9]v``: The 32-bit VGPR register, number 0-9. 4816- ``[0-9]s``: The 32-bit SGPR register, number 0-9. 4817- ``[0-9]a``: The 32-bit AGPR register, number 0-9. 4818- ``I``: An integer inline constant in the range from -16 to 64. 4819- ``J``: A 16-bit signed integer constant. 4820- ``A``: An integer or a floating-point inline constant. 4821- ``B``: A 32-bit signed integer constant. 4822- ``C``: A 32-bit unsigned integer constant or an integer inline constant in the range from -16 to 64. 4823- ``DA``: A 64-bit constant that can be split into two "A" constants. 4824- ``DB``: A 64-bit constant that can be split into two "B" constants. 4825 4826All ARM modes: 4827 4828- ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address 4829 operand. Treated the same as operand ``m``, at the moment. 4830- ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14`` 4831- ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11`` 4832 4833ARM and ARM's Thumb2 mode: 4834 4835- ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``) 4836- ``I``: An immediate integer valid for a data-processing instruction. 4837- ``J``: An immediate integer between -4095 and 4095. 4838- ``K``: An immediate integer whose bitwise inverse is valid for a 4839 data-processing instruction. (Can be used with template modifier "``B``" to 4840 print the inverted value). 4841- ``L``: An immediate integer whose negation is valid for a data-processing 4842 instruction. (Can be used with template modifier "``n``" to print the negated 4843 value). 4844- ``M``: A power of two or an integer between 0 and 32. 4845- ``N``: Invalid immediate constraint. 4846- ``O``: Invalid immediate constraint. 4847- ``r``: A general-purpose 32-bit integer register (``r0-r15``). 4848- ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same 4849 as ``r``. 4850- ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode, 4851 invalid. 4852- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4853 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively. 4854- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4855 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively. 4856- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4857 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively. 4858 4859ARM's Thumb1 mode: 4860 4861- ``I``: An immediate integer between 0 and 255. 4862- ``J``: An immediate integer between -255 and -1. 4863- ``K``: An immediate integer between 0 and 255, with optional left-shift by 4864 some amount. 4865- ``L``: An immediate integer between -7 and 7. 4866- ``M``: An immediate integer which is a multiple of 4 between 0 and 1020. 4867- ``N``: An immediate integer between 0 and 31. 4868- ``O``: An immediate integer which is a multiple of 4 between -508 and 508. 4869- ``r``: A low 32-bit GPR register (``r0-r7``). 4870- ``l``: A low 32-bit GPR register (``r0-r7``). 4871- ``h``: A high GPR register (``r0-r7``). 4872- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4873 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively. 4874- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4875 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively. 4876- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4877 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively. 4878 4879 4880Hexagon: 4881 4882- ``o``, ``v``: A memory address operand, treated the same as constraint ``m``, 4883 at the moment. 4884- ``r``: A 32 or 64-bit register. 4885 4886MSP430: 4887 4888- ``r``: An 8 or 16-bit register. 4889 4890MIPS: 4891 4892- ``I``: An immediate signed 16-bit integer. 4893- ``J``: An immediate integer zero. 4894- ``K``: An immediate unsigned 16-bit integer. 4895- ``L``: An immediate 32-bit integer, where the lower 16 bits are 0. 4896- ``N``: An immediate integer between -65535 and -1. 4897- ``O``: An immediate signed 15-bit integer. 4898- ``P``: An immediate integer between 1 and 65535. 4899- ``m``: A memory address operand. In MIPS-SE mode, allows a base address 4900 register plus 16-bit immediate offset. In MIPS mode, just a base register. 4901- ``R``: A memory address operand. In MIPS-SE mode, allows a base address 4902 register plus a 9-bit signed offset. In MIPS mode, the same as constraint 4903 ``m``. 4904- ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or 4905 ``sc`` instruction on the given subtarget (details vary). 4906- ``r``, ``d``, ``y``: A 32 or 64-bit GPR register. 4907- ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register 4908 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w`` 4909 argument modifier for compatibility with GCC. 4910- ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always 4911 ``25``). 4912- ``l``: The ``lo`` register, 32 or 64-bit. 4913- ``x``: Invalid. 4914 4915NVPTX: 4916 4917- ``b``: A 1-bit integer register. 4918- ``c`` or ``h``: A 16-bit integer register. 4919- ``r``: A 32-bit integer register. 4920- ``l`` or ``N``: A 64-bit integer register. 4921- ``f``: A 32-bit float register. 4922- ``d``: A 64-bit float register. 4923 4924 4925PowerPC: 4926 4927- ``I``: An immediate signed 16-bit integer. 4928- ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits. 4929- ``K``: An immediate unsigned 16-bit integer. 4930- ``L``: An immediate signed 16-bit integer, shifted left 16 bits. 4931- ``M``: An immediate integer greater than 31. 4932- ``N``: An immediate integer that is an exact power of 2. 4933- ``O``: The immediate integer constant 0. 4934- ``P``: An immediate integer constant whose negation is a signed 16-bit 4935 constant. 4936- ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently 4937 treated the same as ``m``. 4938- ``r``: A 32 or 64-bit integer register. 4939- ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is: 4940 ``R1-R31``). 4941- ``f``: A 32 or 64-bit float register (``F0-F31``), 4942- ``v``: For ``4 x f32`` or ``4 x f64`` types, a 128-bit altivec vector 4943 register (``V0-V31``). 4944 4945- ``y``: Condition register (``CR0-CR7``). 4946- ``wc``: An individual CR bit in a CR register. 4947- ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX 4948 register set (overlapping both the floating-point and vector register files). 4949- ``ws``: A 32 or 64-bit floating-point register, from the full VSX register 4950 set. 4951 4952RISC-V: 4953 4954- ``A``: An address operand (using a general-purpose register, without an 4955 offset). 4956- ``I``: A 12-bit signed integer immediate operand. 4957- ``J``: A zero integer immediate operand. 4958- ``K``: A 5-bit unsigned integer immediate operand. 4959- ``f``: A 32- or 64-bit floating-point register (requires F or D extension). 4960- ``r``: A 32- or 64-bit general-purpose register (depending on the platform 4961 ``XLEN``). 4962- ``vr``: A vector register. (requires V extension). 4963- ``vm``: A vector register for masking operand. (requires V extension). 4964 4965Sparc: 4966 4967- ``I``: An immediate 13-bit signed integer. 4968- ``r``: A 32-bit integer register. 4969- ``f``: Any floating-point register on SparcV8, or a floating-point 4970 register in the "low" half of the registers on SparcV9. 4971- ``e``: Any floating-point register. (Same as ``f`` on SparcV8.) 4972 4973SystemZ: 4974 4975- ``I``: An immediate unsigned 8-bit integer. 4976- ``J``: An immediate unsigned 12-bit integer. 4977- ``K``: An immediate signed 16-bit integer. 4978- ``L``: An immediate signed 20-bit integer. 4979- ``M``: An immediate integer 0x7fffffff. 4980- ``Q``: A memory address operand with a base address and a 12-bit immediate 4981 unsigned displacement. 4982- ``R``: A memory address operand with a base address, a 12-bit immediate 4983 unsigned displacement, and an index register. 4984- ``S``: A memory address operand with a base address and a 20-bit immediate 4985 signed displacement. 4986- ``T``: A memory address operand with a base address, a 20-bit immediate 4987 signed displacement, and an index register. 4988- ``r`` or ``d``: A 32, 64, or 128-bit integer register. 4989- ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an 4990 address context evaluates as zero). 4991- ``h``: A 32-bit value in the high part of a 64bit data register 4992 (LLVM-specific) 4993- ``f``: A 32, 64, or 128-bit floating-point register. 4994 4995X86: 4996 4997- ``I``: An immediate integer between 0 and 31. 4998- ``J``: An immediate integer between 0 and 64. 4999- ``K``: An immediate signed 8-bit integer. 5000- ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only) 5001 0xffffffff. 5002- ``M``: An immediate integer between 0 and 3. 5003- ``N``: An immediate unsigned 8-bit integer. 5004- ``O``: An immediate integer between 0 and 127. 5005- ``e``: An immediate 32-bit signed integer. 5006- ``Z``: An immediate 32-bit unsigned integer. 5007- ``o``, ``v``: Treated the same as ``m``, at the moment. 5008- ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 5009 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d`` 5010 registers, and on X86-64, it is all of the integer registers. 5011- ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 5012 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers. 5013- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register. 5014- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has 5015 existed since i386, and can be accessed without the REX prefix. 5016- ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register. 5017- ``y``: A 64-bit MMX register, if MMX is enabled. 5018- ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector 5019 operand in a SSE register. If AVX is also enabled, can also be a 256-bit 5020 vector operand in an AVX register. If AVX-512 is also enabled, can also be a 5021 512-bit vector operand in an AVX512 register, Otherwise, an error. 5022- ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error. 5023- ``A``: Special case: allocates EAX first, then EDX, for a single operand (in 5024 32-bit mode, a 64-bit integer operand will get split into two registers). It 5025 is not recommended to use this constraint, as in 64-bit mode, the 64-bit 5026 operand will get allocated only to RAX -- if two 32-bit operands are needed, 5027 you're better off splitting it yourself, before passing it to the asm 5028 statement. 5029 5030XCore: 5031 5032- ``r``: A 32-bit integer register. 5033 5034 5035.. _inline-asm-modifiers: 5036 5037Asm template argument modifiers 5038^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5039 5040In the asm template string, modifiers can be used on the operand reference, like 5041"``${0:n}``". 5042 5043The modifiers are, in general, expected to behave the same way they do in 5044GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 5045inline asm code which was supported by GCC. A mismatch in behavior between LLVM 5046and GCC likely indicates a bug in LLVM. 5047 5048Target-independent: 5049 5050- ``c``: Print an immediate integer constant unadorned, without 5051 the target-specific immediate punctuation (e.g. no ``$`` prefix). 5052- ``n``: Negate and print immediate integer constant unadorned, without the 5053 target-specific immediate punctuation (e.g. no ``$`` prefix). 5054- ``l``: Print as an unadorned label, without the target-specific label 5055 punctuation (e.g. no ``$`` prefix). 5056 5057AArch64: 5058 5059- ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g., 5060 instead of ``x30``, print ``w30``. 5061- ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow). 5062- ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a 5063 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of 5064 ``v*``. 5065 5066AMDGPU: 5067 5068- ``r``: No effect. 5069 5070ARM: 5071 5072- ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a 5073 register). 5074- ``P``: No effect. 5075- ``q``: No effect. 5076- ``y``: Print a VFP single-precision register as an indexed double (e.g. print 5077 as ``d4[1]`` instead of ``s9``) 5078- ``B``: Bitwise invert and print an immediate integer constant without ``#`` 5079 prefix. 5080- ``L``: Print the low 16-bits of an immediate integer constant. 5081- ``M``: Print as a register set suitable for ldm/stm. Also prints *all* 5082 register operands subsequent to the specified one (!), so use carefully. 5083- ``Q``: Print the low-order register of a register-pair, or the low-order 5084 register of a two-register operand. 5085- ``R``: Print the high-order register of a register-pair, or the high-order 5086 register of a two-register operand. 5087- ``H``: Print the second register of a register-pair. (On a big-endian system, 5088 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent 5089 to ``R``.) 5090 5091 .. FIXME: H doesn't currently support printing the second register 5092 of a two-register operand. 5093 5094- ``e``: Print the low doubleword register of a NEON quad register. 5095- ``f``: Print the high doubleword register of a NEON quad register. 5096- ``m``: Print the base register of a memory operand without the ``[`` and ``]`` 5097 adornment. 5098 5099Hexagon: 5100 5101- ``L``: Print the second register of a two-register operand. Requires that it 5102 has been allocated consecutively to the first. 5103 5104 .. FIXME: why is it restricted to consecutive ones? And there's 5105 nothing that ensures that happens, is there? 5106 5107- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 5108 nothing. Used to print 'addi' vs 'add' instructions. 5109 5110MSP430: 5111 5112No additional modifiers. 5113 5114MIPS: 5115 5116- ``X``: Print an immediate integer as hexadecimal 5117- ``x``: Print the low 16 bits of an immediate integer as hexadecimal. 5118- ``d``: Print an immediate integer as decimal. 5119- ``m``: Subtract one and print an immediate integer as decimal. 5120- ``z``: Print $0 if an immediate zero, otherwise print normally. 5121- ``L``: Print the low-order register of a two-register operand, or prints the 5122 address of the low-order word of a double-word memory operand. 5123 5124 .. FIXME: L seems to be missing memory operand support. 5125 5126- ``M``: Print the high-order register of a two-register operand, or prints the 5127 address of the high-order word of a double-word memory operand. 5128 5129 .. FIXME: M seems to be missing memory operand support. 5130 5131- ``D``: Print the second register of a two-register operand, or prints the 5132 second word of a double-word memory operand. (On a big-endian system, ``D`` is 5133 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to 5134 ``M``.) 5135- ``w``: No effect. Provided for compatibility with GCC which requires this 5136 modifier in order to print MSA registers (``W0-W31``) with the ``f`` 5137 constraint. 5138 5139NVPTX: 5140 5141- ``r``: No effect. 5142 5143PowerPC: 5144 5145- ``L``: Print the second register of a two-register operand. Requires that it 5146 has been allocated consecutively to the first. 5147 5148 .. FIXME: why is it restricted to consecutive ones? And there's 5149 nothing that ensures that happens, is there? 5150 5151- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 5152 nothing. Used to print 'addi' vs 'add' instructions. 5153- ``y``: For a memory operand, prints formatter for a two-register X-form 5154 instruction. (Currently always prints ``r0,OPERAND``). 5155- ``U``: Prints 'u' if the memory operand is an update form, and nothing 5156 otherwise. (NOTE: LLVM does not support update form, so this will currently 5157 always print nothing) 5158- ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does 5159 not support indexed form, so this will currently always print nothing) 5160 5161RISC-V: 5162 5163- ``i``: Print the letter 'i' if the operand is not a register, otherwise print 5164 nothing. Used to print 'addi' vs 'add' instructions, etc. 5165- ``z``: Print the register ``zero`` if an immediate zero, otherwise print 5166 normally. 5167 5168Sparc: 5169 5170- ``r``: No effect. 5171 5172SystemZ: 5173 5174SystemZ implements only ``n``, and does *not* support any of the other 5175target-independent modifiers. 5176 5177X86: 5178 5179- ``c``: Print an unadorned integer or symbol name. (The latter is 5180 target-specific behavior for this typically target-independent modifier). 5181- ``A``: Print a register name with a '``*``' before it. 5182- ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory 5183 operand. 5184- ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a 5185 memory operand. 5186- ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory 5187 operand. 5188- ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory 5189 operand. 5190- ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are 5191 available, otherwise the 32-bit register name; do nothing on a memory operand. 5192- ``n``: Negate and print an unadorned integer, or, for operands other than an 5193 immediate integer (e.g. a relocatable symbol expression), print a '-' before 5194 the operand. (The behavior for relocatable symbol expressions is a 5195 target-specific behavior for this typically target-independent modifier) 5196- ``H``: Print a memory reference with additional offset +8. 5197- ``P``: Print a memory reference used as the argument of a call instruction or 5198 used with explicit base reg and index reg as its offset. So it can not use 5199 additional regs to present the memory reference. (E.g. omit ``(rip)``, even 5200 though it's PC-relative.) 5201 5202XCore: 5203 5204No additional modifiers. 5205 5206 5207Inline Asm Metadata 5208^^^^^^^^^^^^^^^^^^^ 5209 5210The call instructions that wrap inline asm nodes may have a 5211"``!srcloc``" MDNode attached to it that contains a list of constant 5212integers. If present, the code generator will use the integer as the 5213location cookie value when report errors through the ``LLVMContext`` 5214error reporting mechanisms. This allows a front-end to correlate backend 5215errors that occur with inline asm back to the source code that produced 5216it. For example: 5217 5218.. code-block:: llvm 5219 5220 call void asm sideeffect "something bad", ""(), !srcloc !42 5221 ... 5222 !42 = !{ i32 1234567 } 5223 5224It is up to the front-end to make sense of the magic numbers it places 5225in the IR. If the MDNode contains multiple constants, the code generator 5226will use the one that corresponds to the line of the asm that the error 5227occurs on. 5228 5229.. _metadata: 5230 5231Metadata 5232======== 5233 5234LLVM IR allows metadata to be attached to instructions and global objects in the 5235program that can convey extra information about the code to the optimizers and 5236code generator. One example application of metadata is source-level 5237debug information. There are two metadata primitives: strings and nodes. 5238 5239Metadata does not have a type, and is not a value. If referenced from a 5240``call`` instruction, it uses the ``metadata`` type. 5241 5242All metadata are identified in syntax by an exclamation point ('``!``'). 5243 5244.. _metadata-string: 5245 5246Metadata Nodes and Metadata Strings 5247----------------------------------- 5248 5249A metadata string is a string surrounded by double quotes. It can 5250contain any character by escaping non-printable characters with 5251"``\xx``" where "``xx``" is the two digit hex code. For example: 5252"``!"test\00"``". 5253 5254Metadata nodes are represented with notation similar to structure 5255constants (a comma separated list of elements, surrounded by braces and 5256preceded by an exclamation point). Metadata nodes can have any values as 5257their operand. For example: 5258 5259.. code-block:: llvm 5260 5261 !{ !"test\00", i32 10} 5262 5263Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example: 5264 5265.. code-block:: text 5266 5267 !0 = distinct !{!"test\00", i32 10} 5268 5269``distinct`` nodes are useful when nodes shouldn't be merged based on their 5270content. They can also occur when transformations cause uniquing collisions 5271when metadata operands change. 5272 5273A :ref:`named metadata <namedmetadatastructure>` is a collection of 5274metadata nodes, which can be looked up in the module symbol table. For 5275example: 5276 5277.. code-block:: llvm 5278 5279 !foo = !{!4, !3} 5280 5281Metadata can be used as function arguments. Here the ``llvm.dbg.value`` 5282intrinsic is using three metadata arguments: 5283 5284.. code-block:: llvm 5285 5286 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26) 5287 5288Metadata can be attached to an instruction. Here metadata ``!21`` is attached 5289to the ``add`` instruction using the ``!dbg`` identifier: 5290 5291.. code-block:: llvm 5292 5293 %indvar.next = add i64 %indvar, 1, !dbg !21 5294 5295Instructions may not have multiple metadata attachments with the same 5296identifier. 5297 5298Metadata can also be attached to a function or a global variable. Here metadata 5299``!22`` is attached to the ``f1`` and ``f2`` functions, and the globals ``g1`` 5300and ``g2`` using the ``!dbg`` identifier: 5301 5302.. code-block:: llvm 5303 5304 declare !dbg !22 void @f1() 5305 define void @f2() !dbg !22 { 5306 ret void 5307 } 5308 5309 @g1 = global i32 0, !dbg !22 5310 @g2 = external global i32, !dbg !22 5311 5312Unlike instructions, global objects (functions and global variables) may have 5313multiple metadata attachments with the same identifier. 5314 5315A transformation is required to drop any metadata attachment that it does not 5316know or know it can't preserve. Currently there is an exception for metadata 5317attachment to globals for ``!func_sanitize``, ``!type`` and ``!absolute_symbol`` which can't be 5318unconditionally dropped unless the global is itself deleted. 5319 5320Metadata attached to a module using named metadata may not be dropped, with 5321the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``). 5322 5323More information about specific metadata nodes recognized by the 5324optimizers and code generator is found below. 5325 5326.. _specialized-metadata: 5327 5328Specialized Metadata Nodes 5329^^^^^^^^^^^^^^^^^^^^^^^^^^ 5330 5331Specialized metadata nodes are custom data structures in metadata (as opposed 5332to generic tuples). Their fields are labelled, and can be specified in any 5333order. 5334 5335These aren't inherently debug info centric, but currently all the specialized 5336metadata nodes are related to debug info. 5337 5338.. _DICompileUnit: 5339 5340DICompileUnit 5341""""""""""""" 5342 5343``DICompileUnit`` nodes represent a compile unit. The ``enums:``, 5344``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples 5345containing the debug info to be emitted along with the compile unit, regardless 5346of code optimizations (some nodes are only emitted if there are references to 5347them from instructions). The ``debugInfoForProfiling:`` field is a boolean 5348indicating whether or not line-table discriminators are updated to provide 5349more-accurate debug info for profiling results. 5350 5351.. code-block:: text 5352 5353 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", 5354 isOptimized: true, flags: "-O2", runtimeVersion: 2, 5355 splitDebugFilename: "abc.debug", emissionKind: FullDebug, 5356 enums: !2, retainedTypes: !3, globals: !4, imports: !5, 5357 macros: !6, dwoId: 0x0abcd) 5358 5359Compile unit descriptors provide the root scope for objects declared in a 5360specific compilation unit. File descriptors are defined using this scope. These 5361descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep 5362track of global variables, type information, and imported entities (declarations 5363and namespaces). 5364 5365.. _DIFile: 5366 5367DIFile 5368"""""" 5369 5370``DIFile`` nodes represent files. The ``filename:`` can include slashes. 5371 5372.. code-block:: none 5373 5374 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir", 5375 checksumkind: CSK_MD5, 5376 checksum: "000102030405060708090a0b0c0d0e0f") 5377 5378Files are sometimes used in ``scope:`` fields, and are the only valid target 5379for ``file:`` fields. 5380Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1, CSK_SHA256} 5381 5382.. _DIBasicType: 5383 5384DIBasicType 5385""""""""""" 5386 5387``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and 5388``float``. ``tag:`` defaults to ``DW_TAG_base_type``. 5389 5390.. code-block:: text 5391 5392 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 5393 encoding: DW_ATE_unsigned_char) 5394 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)") 5395 5396The ``encoding:`` describes the details of the type. Usually it's one of the 5397following: 5398 5399.. code-block:: text 5400 5401 DW_ATE_address = 1 5402 DW_ATE_boolean = 2 5403 DW_ATE_float = 4 5404 DW_ATE_signed = 5 5405 DW_ATE_signed_char = 6 5406 DW_ATE_unsigned = 7 5407 DW_ATE_unsigned_char = 8 5408 5409.. _DISubroutineType: 5410 5411DISubroutineType 5412"""""""""""""""" 5413 5414``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field 5415refers to a tuple; the first operand is the return type, while the rest are the 5416types of the formal arguments in order. If the first operand is ``null``, that 5417represents a function with no return value (such as ``void foo() {}`` in C++). 5418 5419.. code-block:: text 5420 5421 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed) 5422 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char) 5423 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char) 5424 5425.. _DIDerivedType: 5426 5427DIDerivedType 5428""""""""""""" 5429 5430``DIDerivedType`` nodes represent types derived from other types, such as 5431qualified types. 5432 5433.. code-block:: text 5434 5435 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 5436 encoding: DW_ATE_unsigned_char) 5437 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32, 5438 align: 32) 5439 5440The following ``tag:`` values are valid: 5441 5442.. code-block:: text 5443 5444 DW_TAG_member = 13 5445 DW_TAG_pointer_type = 15 5446 DW_TAG_reference_type = 16 5447 DW_TAG_typedef = 22 5448 DW_TAG_inheritance = 28 5449 DW_TAG_ptr_to_member_type = 31 5450 DW_TAG_const_type = 38 5451 DW_TAG_friend = 42 5452 DW_TAG_volatile_type = 53 5453 DW_TAG_restrict_type = 55 5454 DW_TAG_atomic_type = 71 5455 DW_TAG_immutable_type = 75 5456 5457.. _DIDerivedTypeMember: 5458 5459``DW_TAG_member`` is used to define a member of a :ref:`composite type 5460<DICompositeType>`. The type of the member is the ``baseType:``. The 5461``offset:`` is the member's bit offset. If the composite type has an ODR 5462``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is 5463uniqued based only on its ``name:`` and ``scope:``. 5464 5465``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:`` 5466field of :ref:`composite types <DICompositeType>` to describe parents and 5467friends. 5468 5469``DW_TAG_typedef`` is used to provide a name for the ``baseType:``. 5470 5471``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``, 5472``DW_TAG_volatile_type``, ``DW_TAG_restrict_type``, ``DW_TAG_atomic_type`` and 5473``DW_TAG_immutable_type`` are used to qualify the ``baseType:``. 5474 5475Note that the ``void *`` type is expressed as a type derived from NULL. 5476 5477.. _DICompositeType: 5478 5479DICompositeType 5480""""""""""""""" 5481 5482``DICompositeType`` nodes represent types composed of other types, like 5483structures and unions. ``elements:`` points to a tuple of the composed types. 5484 5485If the source language supports ODR, the ``identifier:`` field gives the unique 5486identifier used for type merging between modules. When specified, 5487:ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member 5488derived types <DIDerivedTypeMember>` that reference the ODR-type in their 5489``scope:`` change uniquing rules. 5490 5491For a given ``identifier:``, there should only be a single composite type that 5492does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules 5493together will unique such definitions at parse time via the ``identifier:`` 5494field, even if the nodes are ``distinct``. 5495 5496.. code-block:: text 5497 5498 !0 = !DIEnumerator(name: "SixKind", value: 7) 5499 !1 = !DIEnumerator(name: "SevenKind", value: 7) 5500 !2 = !DIEnumerator(name: "NegEightKind", value: -8) 5501 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12, 5502 line: 2, size: 32, align: 32, identifier: "_M4Enum", 5503 elements: !{!0, !1, !2}) 5504 5505The following ``tag:`` values are valid: 5506 5507.. code-block:: text 5508 5509 DW_TAG_array_type = 1 5510 DW_TAG_class_type = 2 5511 DW_TAG_enumeration_type = 4 5512 DW_TAG_structure_type = 19 5513 DW_TAG_union_type = 23 5514 5515For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange 5516descriptors <DISubrange>`, each representing the range of subscripts at that 5517level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an 5518array type is a native packed vector. The optional ``dataLocation`` is a 5519DIExpression that describes how to get from an object's address to the actual 5520raw data, if they aren't equivalent. This is only supported for array types, 5521particularly to describe Fortran arrays, which have an array descriptor in 5522addition to the array data. Alternatively it can also be DIVariable which 5523has the address of the actual raw data. The Fortran language supports pointer 5524arrays which can be attached to actual arrays, this attachment between pointer 5525and pointee is called association. The optional ``associated`` is a 5526DIExpression that describes whether the pointer array is currently associated. 5527The optional ``allocated`` is a DIExpression that describes whether the 5528allocatable array is currently allocated. The optional ``rank`` is a 5529DIExpression that describes the rank (number of dimensions) of fortran assumed 5530rank array (rank is known at runtime). 5531 5532For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator 5533descriptors <DIEnumerator>`, each representing the definition of an enumeration 5534value for the set. All enumeration type descriptors are collected in the 5535``enums:`` field of the :ref:`compile unit <DICompileUnit>`. 5536 5537For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and 5538``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types 5539<DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or 5540``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with 5541``isDefinition: false``. 5542 5543.. _DISubrange: 5544 5545DISubrange 5546"""""""""" 5547 5548``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of 5549:ref:`DICompositeType`. 5550 5551- ``count: -1`` indicates an empty array. 5552- ``count: !10`` describes the count with a :ref:`DILocalVariable`. 5553- ``count: !12`` describes the count with a :ref:`DIGlobalVariable`. 5554 5555.. code-block:: text 5556 5557 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0 5558 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1 5559 !2 = !DISubrange(count: -1) ; empty array. 5560 5561 ; Scopes used in rest of example 5562 !6 = !DIFile(filename: "vla.c", directory: "/path/to/file") 5563 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6) 5564 !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5) 5565 5566 ; Use of local variable as count value 5567 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5568 !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9) 5569 !11 = !DISubrange(count: !10, lowerBound: 0) 5570 5571 ; Use of global variable as count value 5572 !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9) 5573 !13 = !DISubrange(count: !12, lowerBound: 0) 5574 5575.. _DIEnumerator: 5576 5577DIEnumerator 5578"""""""""""" 5579 5580``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type`` 5581variants of :ref:`DICompositeType`. 5582 5583.. code-block:: text 5584 5585 !0 = !DIEnumerator(name: "SixKind", value: 7) 5586 !1 = !DIEnumerator(name: "SevenKind", value: 7) 5587 !2 = !DIEnumerator(name: "NegEightKind", value: -8) 5588 5589DITemplateTypeParameter 5590""""""""""""""""""""""" 5591 5592``DITemplateTypeParameter`` nodes represent type parameters to generic source 5593language constructs. They are used (optionally) in :ref:`DICompositeType` and 5594:ref:`DISubprogram` ``templateParams:`` fields. 5595 5596.. code-block:: text 5597 5598 !0 = !DITemplateTypeParameter(name: "Ty", type: !1) 5599 5600DITemplateValueParameter 5601"""""""""""""""""""""""" 5602 5603``DITemplateValueParameter`` nodes represent value parameters to generic source 5604language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``, 5605but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or 5606``DW_TAG_GNU_template_param_pack``. They are used (optionally) in 5607:ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields. 5608 5609.. code-block:: text 5610 5611 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7) 5612 5613DINamespace 5614""""""""""" 5615 5616``DINamespace`` nodes represent namespaces in the source language. 5617 5618.. code-block:: text 5619 5620 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7) 5621 5622.. _DIGlobalVariable: 5623 5624DIGlobalVariable 5625"""""""""""""""" 5626 5627``DIGlobalVariable`` nodes represent global variables in the source language. 5628 5629.. code-block:: text 5630 5631 @foo = global i32, !dbg !0 5632 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 5633 !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2, 5634 file: !3, line: 7, type: !4, isLocal: true, 5635 isDefinition: false, declaration: !5) 5636 5637 5638DIGlobalVariableExpression 5639"""""""""""""""""""""""""" 5640 5641``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together 5642with a :ref:`DIExpression`. 5643 5644.. code-block:: text 5645 5646 @lower = global i32, !dbg !0 5647 @upper = global i32, !dbg !1 5648 !0 = !DIGlobalVariableExpression( 5649 var: !2, 5650 expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32) 5651 ) 5652 !1 = !DIGlobalVariableExpression( 5653 var: !2, 5654 expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32) 5655 ) 5656 !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3, 5657 file: !4, line: 8, type: !5, declaration: !6) 5658 5659All global variable expressions should be referenced by the `globals:` field of 5660a :ref:`compile unit <DICompileUnit>`. 5661 5662.. _DISubprogram: 5663 5664DISubprogram 5665"""""""""""" 5666 5667``DISubprogram`` nodes represent functions from the source language. A distinct 5668``DISubprogram`` may be attached to a function definition using ``!dbg`` 5669metadata. A unique ``DISubprogram`` may be attached to a function declaration 5670used for call site debug info. The ``retainedNodes:`` field is a list of 5671:ref:`variables <DILocalVariable>` and :ref:`labels <DILabel>` that must be 5672retained, even if their IR counterparts are optimized out of the IR. The 5673``type:`` field must point at an :ref:`DISubroutineType`. 5674 5675.. _DISubprogramDeclaration: 5676 5677When ``isDefinition: false``, subprograms describe a declaration in the type 5678tree as opposed to a definition of a function. If the scope is a composite 5679type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, 5680then the subprogram declaration is uniqued based only on its ``linkageName:`` 5681and ``scope:``. 5682 5683.. code-block:: text 5684 5685 define void @_Z3foov() !dbg !0 { 5686 ... 5687 } 5688 5689 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, 5690 file: !2, line: 7, type: !3, isLocal: true, 5691 isDefinition: true, scopeLine: 8, 5692 containingType: !4, 5693 virtuality: DW_VIRTUALITY_pure_virtual, 5694 virtualIndex: 10, flags: DIFlagPrototyped, 5695 isOptimized: true, unit: !5, templateParams: !6, 5696 declaration: !7, retainedNodes: !8, 5697 thrownTypes: !9) 5698 5699.. _DILexicalBlock: 5700 5701DILexicalBlock 5702"""""""""""""" 5703 5704``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram 5705<DISubprogram>`. The line number and column numbers are used to distinguish 5706two lexical blocks at same depth. They are valid targets for ``scope:`` 5707fields. 5708 5709.. code-block:: text 5710 5711 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35) 5712 5713Usually lexical blocks are ``distinct`` to prevent node merging based on 5714operands. 5715 5716.. _DILexicalBlockFile: 5717 5718DILexicalBlockFile 5719"""""""""""""""""" 5720 5721``DILexicalBlockFile`` nodes are used to discriminate between sections of a 5722:ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to 5723indicate textual inclusion, or the ``discriminator:`` field can be used to 5724discriminate between control flow within a single block in the source language. 5725 5726.. code-block:: text 5727 5728 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35) 5729 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0) 5730 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1) 5731 5732.. _DILocation: 5733 5734DILocation 5735"""""""""" 5736 5737``DILocation`` nodes represent source debug locations. The ``scope:`` field is 5738mandatory, and points at an :ref:`DILexicalBlockFile`, an 5739:ref:`DILexicalBlock`, or an :ref:`DISubprogram`. 5740 5741.. code-block:: text 5742 5743 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2) 5744 5745.. _DILocalVariable: 5746 5747DILocalVariable 5748""""""""""""""" 5749 5750``DILocalVariable`` nodes represent local variables in the source language. If 5751the ``arg:`` field is set to non-zero, then this variable is a subprogram 5752parameter, and it will be included in the ``retainedNodes:`` field of its 5753:ref:`DISubprogram`. 5754 5755.. code-block:: text 5756 5757 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7, 5758 type: !3, flags: DIFlagArtificial) 5759 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7, 5760 type: !3) 5761 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3) 5762 5763.. _DIExpression: 5764 5765DIExpression 5766"""""""""""" 5767 5768``DIExpression`` nodes represent expressions that are inspired by the DWARF 5769expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>` 5770(such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the 5771referenced LLVM variable relates to the source language variable. Debug 5772intrinsics are interpreted left-to-right: start by pushing the value/address 5773operand of the intrinsic onto a stack, then repeatedly push and evaluate 5774opcodes from the DIExpression until the final variable description is produced. 5775 5776The current supported opcode vocabulary is limited: 5777 5778- ``DW_OP_deref`` dereferences the top of the expression stack. 5779- ``DW_OP_plus`` pops the last two entries from the expression stack, adds 5780 them together and appends the result to the expression stack. 5781- ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts 5782 the last entry from the second last entry and appends the result to the 5783 expression stack. 5784- ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression. 5785- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8`` 5786 here, respectively) of the variable fragment from the working expression. Note 5787 that contrary to DW_OP_bit_piece, the offset is describing the location 5788 within the described source variable. 5789- ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding 5790 (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the 5791 expression stack is to be converted. Maps into a ``DW_OP_convert`` operation 5792 that references a base type constructed from the supplied values. 5793- ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be 5794 optionally applied to the pointer. The memory tag is derived from the 5795 given tag offset in an implementation-defined manner. 5796- ``DW_OP_swap`` swaps top two stack entries. 5797- ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top 5798 of the stack is treated as an address. The second stack entry is treated as an 5799 address space identifier. 5800- ``DW_OP_stack_value`` marks a constant value. 5801- ``DW_OP_LLVM_entry_value, N`` may only appear in MIR and at the 5802 beginning of a ``DIExpression``. In DWARF a ``DBG_VALUE`` 5803 instruction binding a ``DIExpression(DW_OP_LLVM_entry_value`` to a 5804 register is lowered to a ``DW_OP_entry_value [reg]``, pushing the 5805 value the register had upon function entry onto the stack. The next 5806 ``(N - 1)`` operations will be part of the ``DW_OP_entry_value`` 5807 block argument. For example, ``!DIExpression(DW_OP_LLVM_entry_value, 5808 1, DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an 5809 expression where the entry value of the debug value instruction's 5810 value/address operand is pushed to the stack, and is added 5811 with 123. Due to framework limitations ``N`` can currently only 5812 be 1. 5813 5814 The operation is introduced by the ``LiveDebugValues`` pass, which 5815 applies it only to function parameters that are unmodified 5816 throughout the function. Support is limited to simple register 5817 location descriptions, or as indirect locations (e.g., when a struct 5818 is passed-by-value to a callee via a pointer to a temporary copy 5819 made in the caller). The entry value op is also introduced by the 5820 ``AsmPrinter`` pass when a call site parameter value 5821 (``DW_AT_call_site_parameter_value``) is represented as entry value 5822 of the parameter. 5823- ``DW_OP_LLVM_arg, N`` is used in debug intrinsics that refer to more than one 5824 value, such as one that calculates the sum of two registers. This is always 5825 used in combination with an ordered list of values, such that 5826 ``DW_OP_LLVM_arg, N`` refers to the ``N``th element in that list. For 5827 example, ``!DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus, 5828 DW_OP_stack_value)`` used with the list ``(%reg1, %reg2)`` would evaluate to 5829 ``%reg1 - reg2``. This list of values should be provided by the containing 5830 intrinsic/instruction. 5831- ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided 5832 signed offset of the specified register. The opcode is only generated by the 5833 ``AsmPrinter`` pass to describe call site parameter value which requires an 5834 expression over two registers. 5835- ``DW_OP_push_object_address`` pushes the address of the object which can then 5836 serve as a descriptor in subsequent calculation. This opcode can be used to 5837 calculate bounds of fortran allocatable array which has array descriptors. 5838- ``DW_OP_over`` duplicates the entry currently second in the stack at the top 5839 of the stack. This opcode can be used to calculate bounds of fortran assumed 5840 rank array which has rank known at run time and current dimension number is 5841 implicitly first element of the stack. 5842- ``DW_OP_LLVM_implicit_pointer`` It specifies the dereferenced value. It can 5843 be used to represent pointer variables which are optimized out but the value 5844 it points to is known. This operator is required as it is different than DWARF 5845 operator DW_OP_implicit_pointer in representation and specification (number 5846 and types of operands) and later can not be used as multiple level. 5847 5848.. code-block:: text 5849 5850 IR for "*ptr = 4;" 5851 -------------- 5852 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !20) 5853 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5, 5854 type: !18) 5855 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64) 5856 !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5857 !20 = !DIExpression(DW_OP_LLVM_implicit_pointer)) 5858 5859 IR for "**ptr = 4;" 5860 -------------- 5861 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !21) 5862 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5, 5863 type: !18) 5864 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64) 5865 !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64) 5866 !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5867 !21 = !DIExpression(DW_OP_LLVM_implicit_pointer, 5868 DW_OP_LLVM_implicit_pointer)) 5869 5870DWARF specifies three kinds of simple location descriptions: Register, memory, 5871and implicit location descriptions. Note that a location description is 5872defined over certain ranges of a program, i.e the location of a variable may 5873change over the course of the program. Register and memory location 5874descriptions describe the *concrete location* of a source variable (in the 5875sense that a debugger might modify its value), whereas *implicit locations* 5876describe merely the actual *value* of a source variable which might not exist 5877in registers or in memory (see ``DW_OP_stack_value``). 5878 5879A ``llvm.dbg.addr`` or ``llvm.dbg.declare`` intrinsic describes an indirect 5880value (the address) of a source variable. The first operand of the intrinsic 5881must be an address of some kind. A DIExpression attached to the intrinsic 5882refines this address to produce a concrete location for the source variable. 5883 5884A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable. 5885The first operand of the intrinsic may be a direct or indirect value. A 5886DIExpression attached to the intrinsic refines the first operand to produce a 5887direct value. For example, if the first operand is an indirect value, it may be 5888necessary to insert ``DW_OP_deref`` into the DIExpression in order to produce a 5889valid debug intrinsic. 5890 5891.. note:: 5892 5893 A DIExpression is interpreted in the same way regardless of which kind of 5894 debug intrinsic it's attached to. 5895 5896.. code-block:: text 5897 5898 !0 = !DIExpression(DW_OP_deref) 5899 !1 = !DIExpression(DW_OP_plus_uconst, 3) 5900 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus) 5901 !2 = !DIExpression(DW_OP_bit_piece, 3, 7) 5902 !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7) 5903 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef) 5904 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value) 5905 5906DIArgList 5907"""""""""""" 5908 5909``DIArgList`` nodes hold a list of constant or SSA value references. These are 5910used in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in 5911``llvm.dbg.value``) in combination with a ``DIExpression`` that uses the 5912``DW_OP_LLVM_arg`` operator. Because a DIArgList may refer to local values 5913within a function, it must only be used as a function argument, must always be 5914inlined, and cannot appear in named metadata. 5915 5916.. code-block:: text 5917 5918 llvm.dbg.value(metadata !DIArgList(i32 %a, i32 %b), 5919 metadata !16, 5920 metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus)) 5921 5922DIFlags 5923""""""""""""""" 5924 5925These flags encode various properties of DINodes. 5926 5927The `ExportSymbols` flag marks a class, struct or union whose members 5928may be referenced as if they were defined in the containing class or 5929union. This flag is used to decide whether the DW_AT_export_symbols can 5930be used for the structure type. 5931 5932DIObjCProperty 5933"""""""""""""" 5934 5935``DIObjCProperty`` nodes represent Objective-C property nodes. 5936 5937.. code-block:: text 5938 5939 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo", 5940 getter: "getFoo", attributes: 7, type: !2) 5941 5942DIImportedEntity 5943"""""""""""""""" 5944 5945``DIImportedEntity`` nodes represent entities (such as modules) imported into a 5946compile unit. The ``elements`` field is a list of renamed entities (such as 5947variables and subprograms) in the imported entity (such as module). 5948 5949.. code-block:: text 5950 5951 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0, 5952 entity: !1, line: 7, elements: !3) 5953 !3 = !{!4} 5954 !4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "bar", scope: !0, 5955 entity: !5, line: 7) 5956 5957DIMacro 5958""""""" 5959 5960``DIMacro`` nodes represent definition or undefinition of a macro identifiers. 5961The ``name:`` field is the macro identifier, followed by macro parameters when 5962defining a function-like macro, and the ``value`` field is the token-string 5963used to expand the macro identifier. 5964 5965.. code-block:: text 5966 5967 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)", 5968 value: "((x) + 1)") 5969 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo") 5970 5971DIMacroFile 5972""""""""""" 5973 5974``DIMacroFile`` nodes represent inclusion of source files. 5975The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that 5976appear in the included source file. 5977 5978.. code-block:: text 5979 5980 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2, 5981 nodes: !3) 5982 5983.. _DILabel: 5984 5985DILabel 5986""""""" 5987 5988``DILabel`` nodes represent labels within a :ref:`DISubprogram`. All fields of 5989a ``DILabel`` are mandatory. The ``scope:`` field must be one of either a 5990:ref:`DILexicalBlockFile`, a :ref:`DILexicalBlock`, or a :ref:`DISubprogram`. 5991The ``name:`` field is the label identifier. The ``file:`` field is the 5992:ref:`DIFile` the label is present in. The ``line:`` field is the source line 5993within the file where the label is declared. 5994 5995.. code-block:: text 5996 5997 !2 = !DILabel(scope: !0, name: "foo", file: !1, line: 7) 5998 5999'``tbaa``' Metadata 6000^^^^^^^^^^^^^^^^^^^ 6001 6002In LLVM IR, memory does not have types, so LLVM's own type system is not 6003suitable for doing type based alias analysis (TBAA). Instead, metadata is 6004added to the IR to describe a type system of a higher level language. This 6005can be used to implement C/C++ strict type aliasing rules, but it can also 6006be used to implement custom alias analysis behavior for other languages. 6007 6008This description of LLVM's TBAA system is broken into two parts: 6009:ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and 6010:ref:`Representation<tbaa_node_representation>` talks about the metadata 6011encoding of various entities. 6012 6013It is always possible to trace any TBAA node to a "root" TBAA node (details 6014in the :ref:`Representation<tbaa_node_representation>` section). TBAA 6015nodes with different roots have an unknown aliasing relationship, and LLVM 6016conservatively infers ``MayAlias`` between them. The rules mentioned in 6017this section only pertain to TBAA nodes living under the same root. 6018 6019.. _tbaa_node_semantics: 6020 6021Semantics 6022""""""""" 6023 6024The TBAA metadata system, referred to as "struct path TBAA" (not to be 6025confused with ``tbaa.struct``), consists of the following high level 6026concepts: *Type Descriptors*, further subdivided into scalar type 6027descriptors and struct type descriptors; and *Access Tags*. 6028 6029**Type descriptors** describe the type system of the higher level language 6030being compiled. **Scalar type descriptors** describe types that do not 6031contain other types. Each scalar type has a parent type, which must also 6032be a scalar type or the TBAA root. Via this parent relation, scalar types 6033within a TBAA root form a tree. **Struct type descriptors** denote types 6034that contain a sequence of other type descriptors, at known offsets. These 6035contained type descriptors can either be struct type descriptors themselves 6036or scalar type descriptors. 6037 6038**Access tags** are metadata nodes attached to load and store instructions. 6039Access tags use type descriptors to describe the *location* being accessed 6040in terms of the type system of the higher level language. Access tags are 6041tuples consisting of a base type, an access type and an offset. The base 6042type is a scalar type descriptor or a struct type descriptor, the access 6043type is a scalar type descriptor, and the offset is a constant integer. 6044 6045The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two 6046things: 6047 6048 * If ``BaseTy`` is a struct type, the tag describes a memory access (load 6049 or store) of a value of type ``AccessTy`` contained in the struct type 6050 ``BaseTy`` at offset ``Offset``. 6051 6052 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and 6053 ``AccessTy`` must be the same; and the access tag describes a scalar 6054 access with scalar type ``AccessTy``. 6055 6056We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)`` 6057tuples this way: 6058 6059 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is 6060 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as 6061 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is 6062 undefined if ``Offset`` is non-zero. 6063 6064 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)`` 6065 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in 6066 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted 6067 to be relative within that inner type. 6068 6069A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)`` 6070aliases a memory access with an access tag ``(BaseTy2, AccessTy2, 6071Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2, 6072Offset2)`` via the ``Parent`` relation or vice versa. 6073 6074As a concrete example, the type descriptor graph for the following program 6075 6076.. code-block:: c 6077 6078 struct Inner { 6079 int i; // offset 0 6080 float f; // offset 4 6081 }; 6082 6083 struct Outer { 6084 float f; // offset 0 6085 double d; // offset 4 6086 struct Inner inner_a; // offset 12 6087 }; 6088 6089 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) { 6090 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0) 6091 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12) 6092 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16) 6093 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0) 6094 } 6095 6096is (note that in C and C++, ``char`` can be used to access any arbitrary 6097type): 6098 6099.. code-block:: text 6100 6101 Root = "TBAA Root" 6102 CharScalarTy = ("char", Root, 0) 6103 FloatScalarTy = ("float", CharScalarTy, 0) 6104 DoubleScalarTy = ("double", CharScalarTy, 0) 6105 IntScalarTy = ("int", CharScalarTy, 0) 6106 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)} 6107 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4), 6108 (InnerStructTy, 12)} 6109 6110 6111with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy, 61120)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and 6113``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``. 6114 6115.. _tbaa_node_representation: 6116 6117Representation 6118"""""""""""""" 6119 6120The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or 6121with exactly one ``MDString`` operand. 6122 6123Scalar type descriptors are represented as an ``MDNode`` s with two 6124operands. The first operand is an ``MDString`` denoting the name of the 6125struct type. LLVM does not assign meaning to the value of this operand, it 6126only cares about it being an ``MDString``. The second operand is an 6127``MDNode`` which points to the parent for said scalar type descriptor, 6128which is either another scalar type descriptor or the TBAA root. Scalar 6129type descriptors can have an optional third argument, but that must be the 6130constant integer zero. 6131 6132Struct type descriptors are represented as ``MDNode`` s with an odd number 6133of operands greater than 1. The first operand is an ``MDString`` denoting 6134the name of the struct type. Like in scalar type descriptors the actual 6135value of this name operand is irrelevant to LLVM. After the name operand, 6136the struct type descriptors have a sequence of alternating ``MDNode`` and 6137``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand, 6138an ``MDNode``, denotes a contained field, and the 2N th operand, a 6139``ConstantInt``, is the offset of the said contained field. The offsets 6140must be in non-decreasing order. 6141 6142Access tags are represented as ``MDNode`` s with either 3 or 4 operands. 6143The first operand is an ``MDNode`` pointing to the node representing the 6144base type. The second operand is an ``MDNode`` pointing to the node 6145representing the access type. The third operand is a ``ConstantInt`` that 6146states the offset of the access. If a fourth field is present, it must be 6147a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states 6148that the location being accessed is "constant" (meaning 6149``pointsToConstantMemory`` should return true; see `other useful 6150AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of 6151the access type and the base type of an access tag must be the same, and 6152that is the TBAA root of the access tag. 6153 6154'``tbaa.struct``' Metadata 6155^^^^^^^^^^^^^^^^^^^^^^^^^^ 6156 6157The :ref:`llvm.memcpy <int_memcpy>` is often used to implement 6158aggregate assignment operations in C and similar languages, however it 6159is defined to copy a contiguous region of memory, which is more than 6160strictly necessary for aggregate types which contain holes due to 6161padding. Also, it doesn't contain any TBAA information about the fields 6162of the aggregate. 6163 6164``!tbaa.struct`` metadata can describe which memory subregions in a 6165memcpy are padding and what the TBAA tags of the struct are. 6166 6167The current metadata format is very simple. ``!tbaa.struct`` metadata 6168nodes are a list of operands which are in conceptual groups of three. 6169For each group of three, the first operand gives the byte offset of a 6170field in bytes, the second gives its size in bytes, and the third gives 6171its tbaa tag. e.g.: 6172 6173.. code-block:: llvm 6174 6175 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 } 6176 6177This describes a struct with two fields. The first is at offset 0 bytes 6178with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes 6179and has size 4 bytes and has tbaa tag !2. 6180 6181Note that the fields need not be contiguous. In this example, there is a 61824 byte gap between the two fields. This gap represents padding which 6183does not carry useful data and need not be preserved. 6184 6185'``noalias``' and '``alias.scope``' Metadata 6186^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6187 6188``noalias`` and ``alias.scope`` metadata provide the ability to specify generic 6189noalias memory-access sets. This means that some collection of memory access 6190instructions (loads, stores, memory-accessing calls, etc.) that carry 6191``noalias`` metadata can specifically be specified not to alias with some other 6192collection of memory access instructions that carry ``alias.scope`` metadata. 6193Each type of metadata specifies a list of scopes where each scope has an id and 6194a domain. 6195 6196When evaluating an aliasing query, if for some domain, the set 6197of scopes with that domain in one instruction's ``alias.scope`` list is a 6198subset of (or equal to) the set of scopes for that domain in another 6199instruction's ``noalias`` list, then the two memory accesses are assumed not to 6200alias. 6201 6202Because scopes in one domain don't affect scopes in other domains, separate 6203domains can be used to compose multiple independent noalias sets. This is 6204used for example during inlining. As the noalias function parameters are 6205turned into noalias scope metadata, a new domain is used every time the 6206function is inlined. 6207 6208The metadata identifying each domain is itself a list containing one or two 6209entries. The first entry is the name of the domain. Note that if the name is a 6210string then it can be combined across functions and translation units. A 6211self-reference can be used to create globally unique domain names. A 6212descriptive string may optionally be provided as a second list entry. 6213 6214The metadata identifying each scope is also itself a list containing two or 6215three entries. The first entry is the name of the scope. Note that if the name 6216is a string then it can be combined across functions and translation units. A 6217self-reference can be used to create globally unique scope names. A metadata 6218reference to the scope's domain is the second entry. A descriptive string may 6219optionally be provided as a third list entry. 6220 6221For example, 6222 6223.. code-block:: llvm 6224 6225 ; Two scope domains: 6226 !0 = !{!0} 6227 !1 = !{!1} 6228 6229 ; Some scopes in these domains: 6230 !2 = !{!2, !0} 6231 !3 = !{!3, !0} 6232 !4 = !{!4, !1} 6233 6234 ; Some scope lists: 6235 !5 = !{!4} ; A list containing only scope !4 6236 !6 = !{!4, !3, !2} 6237 !7 = !{!3} 6238 6239 ; These two instructions don't alias: 6240 %0 = load float, float* %c, align 4, !alias.scope !5 6241 store float %0, float* %arrayidx.i, align 4, !noalias !5 6242 6243 ; These two instructions also don't alias (for domain !1, the set of scopes 6244 ; in the !alias.scope equals that in the !noalias list): 6245 %2 = load float, float* %c, align 4, !alias.scope !5 6246 store float %2, float* %arrayidx.i2, align 4, !noalias !6 6247 6248 ; These two instructions may alias (for domain !0, the set of scopes in 6249 ; the !noalias list is not a superset of, or equal to, the scopes in the 6250 ; !alias.scope list): 6251 %2 = load float, float* %c, align 4, !alias.scope !6 6252 store float %0, float* %arrayidx.i, align 4, !noalias !7 6253 6254'``fpmath``' Metadata 6255^^^^^^^^^^^^^^^^^^^^^ 6256 6257``fpmath`` metadata may be attached to any instruction of floating-point 6258type. It can be used to express the maximum acceptable error in the 6259result of that instruction, in ULPs, thus potentially allowing the 6260compiler to use a more efficient but less accurate method of computing 6261it. ULP is defined as follows: 6262 6263 If ``x`` is a real number that lies between two finite consecutive 6264 floating-point numbers ``a`` and ``b``, without being equal to one 6265 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the 6266 distance between the two non-equal finite floating-point numbers 6267 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``. 6268 6269The metadata node shall consist of a single positive float type number 6270representing the maximum relative error, for example: 6271 6272.. code-block:: llvm 6273 6274 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs 6275 6276.. _range-metadata: 6277 6278'``range``' Metadata 6279^^^^^^^^^^^^^^^^^^^^ 6280 6281``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of 6282integer types. It expresses the possible ranges the loaded value or the value 6283returned by the called function at this call site is in. If the loaded or 6284returned value is not in the specified range, the behavior is undefined. The 6285ranges are represented with a flattened list of integers. The loaded value or 6286the value returned is known to be in the union of the ranges defined by each 6287consecutive pair. Each pair has the following properties: 6288 6289- The type must match the type loaded by the instruction. 6290- The pair ``a,b`` represents the range ``[a,b)``. 6291- Both ``a`` and ``b`` are constants. 6292- The range is allowed to wrap. 6293- The range should not represent the full or empty set. That is, 6294 ``a!=b``. 6295 6296In addition, the pairs must be in signed order of the lower bound and 6297they must be non-contiguous. 6298 6299Examples: 6300 6301.. code-block:: llvm 6302 6303 %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1 6304 %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1 6305 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5 6306 %d = invoke i8 @bar() to label %cont 6307 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5 6308 ... 6309 !0 = !{ i8 0, i8 2 } 6310 !1 = !{ i8 255, i8 2 } 6311 !2 = !{ i8 0, i8 2, i8 3, i8 6 } 6312 !3 = !{ i8 -2, i8 0, i8 3, i8 6 } 6313 6314'``absolute_symbol``' Metadata 6315^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6316 6317``absolute_symbol`` metadata may be attached to a global variable 6318declaration. It marks the declaration as a reference to an absolute symbol, 6319which causes the backend to use absolute relocations for the symbol even 6320in position independent code, and expresses the possible ranges that the 6321global variable's *address* (not its value) is in, in the same format as 6322``range`` metadata, with the extension that the pair ``all-ones,all-ones`` 6323may be used to represent the full set. 6324 6325Example (assuming 64-bit pointers): 6326 6327.. code-block:: llvm 6328 6329 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256) 6330 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64) 6331 6332 ... 6333 !0 = !{ i64 0, i64 256 } 6334 !1 = !{ i64 -1, i64 -1 } 6335 6336'``callees``' Metadata 6337^^^^^^^^^^^^^^^^^^^^^^ 6338 6339``callees`` metadata may be attached to indirect call sites. If ``callees`` 6340metadata is attached to a call site, and any callee is not among the set of 6341functions provided by the metadata, the behavior is undefined. The intent of 6342this metadata is to facilitate optimizations such as indirect-call promotion. 6343For example, in the code below, the call instruction may only target the 6344``add`` or ``sub`` functions: 6345 6346.. code-block:: llvm 6347 6348 %result = call i64 %binop(i64 %x, i64 %y), !callees !0 6349 6350 ... 6351 !0 = !{i64 (i64, i64)* @add, i64 (i64, i64)* @sub} 6352 6353'``callback``' Metadata 6354^^^^^^^^^^^^^^^^^^^^^^^ 6355 6356``callback`` metadata may be attached to a function declaration, or definition. 6357(Call sites are excluded only due to the lack of a use case.) For ease of 6358exposition, we'll refer to the function annotated w/ metadata as a broker 6359function. The metadata describes how the arguments of a call to the broker are 6360in turn passed to the callback function specified by the metadata. Thus, the 6361``callback`` metadata provides a partial description of a call site inside the 6362broker function with regards to the arguments of a call to the broker. The only 6363semantic restriction on the broker function itself is that it is not allowed to 6364inspect or modify arguments referenced in the ``callback`` metadata as 6365pass-through to the callback function. 6366 6367The broker is not required to actually invoke the callback function at runtime. 6368However, the assumptions about not inspecting or modifying arguments that would 6369be passed to the specified callback function still hold, even if the callback 6370function is not dynamically invoked. The broker is allowed to invoke the 6371callback function more than once per invocation of the broker. The broker is 6372also allowed to invoke (directly or indirectly) the function passed as a 6373callback through another use. Finally, the broker is also allowed to relay the 6374callback callee invocation to a different thread. 6375 6376The metadata is structured as follows: At the outer level, ``callback`` 6377metadata is a list of ``callback`` encodings. Each encoding starts with a 6378constant ``i64`` which describes the argument position of the callback function 6379in the call to the broker. The following elements, except the last, describe 6380what arguments are passed to the callback function. Each element is again an 6381``i64`` constant identifying the argument of the broker that is passed through, 6382or ``i64 -1`` to indicate an unknown or inspected argument. The order in which 6383they are listed has to be the same in which they are passed to the callback 6384callee. The last element of the encoding is a boolean which specifies how 6385variadic arguments of the broker are handled. If it is true, all variadic 6386arguments of the broker are passed through to the callback function *after* the 6387arguments encoded explicitly before. 6388 6389In the code below, the ``pthread_create`` function is marked as a broker 6390through the ``!callback !1`` metadata. In the example, there is only one 6391callback encoding, namely ``!2``, associated with the broker. This encoding 6392identifies the callback function as the second argument of the broker (``i64 63932``) and the sole argument of the callback function as the third one of the 6394broker function (``i64 3``). 6395 6396.. FIXME why does the llvm-sphinx-docs builder give a highlighting 6397 error if the below is set to highlight as 'llvm', despite that we 6398 have misc.highlighting_failure set? 6399 6400.. code-block:: text 6401 6402 declare !callback !1 dso_local i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*) 6403 6404 ... 6405 !2 = !{i64 2, i64 3, i1 false} 6406 !1 = !{!2} 6407 6408Another example is shown below. The callback callee is the second argument of 6409the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown 6410values (each identified by a ``i64 -1``) and afterwards all 6411variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the 6412final ``i1 true``). 6413 6414.. FIXME why does the llvm-sphinx-docs builder give a highlighting 6415 error if the below is set to highlight as 'llvm', despite that we 6416 have misc.highlighting_failure set? 6417 6418.. code-block:: text 6419 6420 declare !callback !0 dso_local void @__kmpc_fork_call(%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) 6421 6422 ... 6423 !1 = !{i64 2, i64 -1, i64 -1, i1 true} 6424 !0 = !{!1} 6425 6426'``exclude``' Metadata 6427^^^^^^^^^^^^^^^^^^^^^^ 6428 6429``exclude`` metadata may be attached to a global variable to signify that its 6430section should not be included in the final executable or shared library. This 6431option is only valid for global variables with an explicit section targeting ELF 6432or COFF. This is done using the ``SHF_EXCLUDE`` flag on ELF targets and the 6433``IMAGE_SCN_LNK_REMOVE`` and ``IMAGE_SCN_MEM_DISCARDABLE`` flags for COFF 6434targets. Additionally, this metadata is only used as a flag, so the associated 6435node must be empty. The explicit section should not conflict with any other 6436sections that the user does not want removed after linking. 6437 6438.. code-block:: text 6439 6440 @object = private constant [1 x i8] c"\00", section ".foo" !exclude !0 6441 6442 ... 6443 !0 = !{} 6444 6445'``unpredictable``' Metadata 6446^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6447 6448``unpredictable`` metadata may be attached to any branch or switch 6449instruction. It can be used to express the unpredictability of control 6450flow. Similar to the llvm.expect intrinsic, it may be used to alter 6451optimizations related to compare and branch instructions. The metadata 6452is treated as a boolean value; if it exists, it signals that the branch 6453or switch that it is attached to is completely unpredictable. 6454 6455.. _md_dereferenceable: 6456 6457'``dereferenceable``' Metadata 6458^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6459 6460The existence of the ``!dereferenceable`` metadata on the instruction 6461tells the optimizer that the value loaded is known to be dereferenceable. 6462The number of bytes known to be dereferenceable is specified by the integer 6463value in the metadata node. This is analogous to the ''dereferenceable'' 6464attribute on parameters and return values. 6465 6466.. _md_dereferenceable_or_null: 6467 6468'``dereferenceable_or_null``' Metadata 6469^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6470 6471The existence of the ``!dereferenceable_or_null`` metadata on the 6472instruction tells the optimizer that the value loaded is known to be either 6473dereferenceable or null. 6474The number of bytes known to be dereferenceable is specified by the integer 6475value in the metadata node. This is analogous to the ''dereferenceable_or_null'' 6476attribute on parameters and return values. 6477 6478.. _llvm.loop: 6479 6480'``llvm.loop``' 6481^^^^^^^^^^^^^^^ 6482 6483It is sometimes useful to attach information to loop constructs. Currently, 6484loop metadata is implemented as metadata attached to the branch instruction 6485in the loop latch block. The loop metadata node is a list of 6486other metadata nodes, each representing a property of the loop. Usually, 6487the first item of the property node is a string. For example, the 6488``llvm.loop.unroll.count`` suggests an unroll factor to the loop 6489unroller: 6490 6491.. code-block:: llvm 6492 6493 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0 6494 ... 6495 !0 = !{!0, !1, !2} 6496 !1 = !{!"llvm.loop.unroll.enable"} 6497 !2 = !{!"llvm.loop.unroll.count", i32 4} 6498 6499For legacy reasons, the first item of a loop metadata node must be a 6500reference to itself. Before the advent of the 'distinct' keyword, this 6501forced the preservation of otherwise identical metadata nodes. Since 6502the loop-metadata node can be attached to multiple nodes, the 'distinct' 6503keyword has become unnecessary. 6504 6505Prior to the property nodes, one or two ``DILocation`` (debug location) 6506nodes can be present in the list. The first, if present, identifies the 6507source-code location where the loop begins. The second, if present, 6508identifies the source-code location where the loop ends. 6509 6510Loop metadata nodes cannot be used as unique identifiers. They are 6511neither persistent for the same loop through transformations nor 6512necessarily unique to just one loop. 6513 6514'``llvm.loop.disable_nonforced``' 6515^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6516 6517This metadata disables all optional loop transformations unless 6518explicitly instructed using other transformation metadata such as 6519``llvm.loop.unroll.enable``. That is, no heuristic will try to determine 6520whether a transformation is profitable. The purpose is to avoid that the 6521loop is transformed to a different loop before an explicitly requested 6522(forced) transformation is applied. For instance, loop fusion can make 6523other transformations impossible. Mandatory loop canonicalizations such 6524as loop rotation are still applied. 6525 6526It is recommended to use this metadata in addition to any llvm.loop.* 6527transformation directive. Also, any loop should have at most one 6528directive applied to it (and a sequence of transformations built using 6529followup-attributes). Otherwise, which transformation will be applied 6530depends on implementation details such as the pass pipeline order. 6531 6532See :ref:`transformation-metadata` for details. 6533 6534'``llvm.loop.vectorize``' and '``llvm.loop.interleave``' 6535^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6536 6537Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are 6538used to control per-loop vectorization and interleaving parameters such as 6539vectorization width and interleave count. These metadata should be used in 6540conjunction with ``llvm.loop`` loop identification metadata. The 6541``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only 6542optimization hints and the optimizer will only interleave and vectorize loops if 6543it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata 6544which contains information about loop-carried memory dependencies can be helpful 6545in determining the safety of these transformations. 6546 6547'``llvm.loop.interleave.count``' Metadata 6548^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6549 6550This metadata suggests an interleave count to the loop interleaver. 6551The first operand is the string ``llvm.loop.interleave.count`` and the 6552second operand is an integer specifying the interleave count. For 6553example: 6554 6555.. code-block:: llvm 6556 6557 !0 = !{!"llvm.loop.interleave.count", i32 4} 6558 6559Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving 6560multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0 6561then the interleave count will be determined automatically. 6562 6563'``llvm.loop.vectorize.enable``' Metadata 6564^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6565 6566This metadata selectively enables or disables vectorization for the loop. The 6567first operand is the string ``llvm.loop.vectorize.enable`` and the second operand 6568is a bit. If the bit operand value is 1 vectorization is enabled. A value of 65690 disables vectorization: 6570 6571.. code-block:: llvm 6572 6573 !0 = !{!"llvm.loop.vectorize.enable", i1 0} 6574 !1 = !{!"llvm.loop.vectorize.enable", i1 1} 6575 6576'``llvm.loop.vectorize.predicate.enable``' Metadata 6577^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6578 6579This metadata selectively enables or disables creating predicated instructions 6580for the loop, which can enable folding of the scalar epilogue loop into the 6581main loop. The first operand is the string 6582``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If 6583the bit operand value is 1 vectorization is enabled. A value of 0 disables 6584vectorization: 6585 6586.. code-block:: llvm 6587 6588 !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0} 6589 !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1} 6590 6591'``llvm.loop.vectorize.scalable.enable``' Metadata 6592^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6593 6594This metadata selectively enables or disables scalable vectorization for the 6595loop, and only has any effect if vectorization for the loop is already enabled. 6596The first operand is the string ``llvm.loop.vectorize.scalable.enable`` 6597and the second operand is a bit. If the bit operand value is 1 scalable 6598vectorization is enabled, whereas a value of 0 reverts to the default fixed 6599width vectorization: 6600 6601.. code-block:: llvm 6602 6603 !0 = !{!"llvm.loop.vectorize.scalable.enable", i1 0} 6604 !1 = !{!"llvm.loop.vectorize.scalable.enable", i1 1} 6605 6606'``llvm.loop.vectorize.width``' Metadata 6607^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6608 6609This metadata sets the target width of the vectorizer. The first 6610operand is the string ``llvm.loop.vectorize.width`` and the second 6611operand is an integer specifying the width. For example: 6612 6613.. code-block:: llvm 6614 6615 !0 = !{!"llvm.loop.vectorize.width", i32 4} 6616 6617Note that setting ``llvm.loop.vectorize.width`` to 1 disables 6618vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to 66190 or if the loop does not have this metadata the width will be 6620determined automatically. 6621 6622'``llvm.loop.vectorize.followup_vectorized``' Metadata 6623^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6624 6625This metadata defines which loop attributes the vectorized loop will 6626have. See :ref:`transformation-metadata` for details. 6627 6628'``llvm.loop.vectorize.followup_epilogue``' Metadata 6629^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6630 6631This metadata defines which loop attributes the epilogue will have. The 6632epilogue is not vectorized and is executed when either the vectorized 6633loop is not known to preserve semantics (because e.g., it processes two 6634arrays that are found to alias by a runtime check) or for the last 6635iterations that do not fill a complete set of vector lanes. See 6636:ref:`Transformation Metadata <transformation-metadata>` for details. 6637 6638'``llvm.loop.vectorize.followup_all``' Metadata 6639^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6640 6641Attributes in the metadata will be added to both the vectorized and 6642epilogue loop. 6643See :ref:`Transformation Metadata <transformation-metadata>` for details. 6644 6645'``llvm.loop.unroll``' 6646^^^^^^^^^^^^^^^^^^^^^^ 6647 6648Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling 6649optimization hints such as the unroll factor. ``llvm.loop.unroll`` 6650metadata should be used in conjunction with ``llvm.loop`` loop 6651identification metadata. The ``llvm.loop.unroll`` metadata are only 6652optimization hints and the unrolling will only be performed if the 6653optimizer believes it is safe to do so. 6654 6655'``llvm.loop.unroll.count``' Metadata 6656^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6657 6658This metadata suggests an unroll factor to the loop unroller. The 6659first operand is the string ``llvm.loop.unroll.count`` and the second 6660operand is a positive integer specifying the unroll factor. For 6661example: 6662 6663.. code-block:: llvm 6664 6665 !0 = !{!"llvm.loop.unroll.count", i32 4} 6666 6667If the trip count of the loop is less than the unroll count the loop 6668will be partially unrolled. 6669 6670'``llvm.loop.unroll.disable``' Metadata 6671^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6672 6673This metadata disables loop unrolling. The metadata has a single operand 6674which is the string ``llvm.loop.unroll.disable``. For example: 6675 6676.. code-block:: llvm 6677 6678 !0 = !{!"llvm.loop.unroll.disable"} 6679 6680'``llvm.loop.unroll.runtime.disable``' Metadata 6681^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6682 6683This metadata disables runtime loop unrolling. The metadata has a single 6684operand which is the string ``llvm.loop.unroll.runtime.disable``. For example: 6685 6686.. code-block:: llvm 6687 6688 !0 = !{!"llvm.loop.unroll.runtime.disable"} 6689 6690'``llvm.loop.unroll.enable``' Metadata 6691^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6692 6693This metadata suggests that the loop should be fully unrolled if the trip count 6694is known at compile time and partially unrolled if the trip count is not known 6695at compile time. The metadata has a single operand which is the string 6696``llvm.loop.unroll.enable``. For example: 6697 6698.. code-block:: llvm 6699 6700 !0 = !{!"llvm.loop.unroll.enable"} 6701 6702'``llvm.loop.unroll.full``' Metadata 6703^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6704 6705This metadata suggests that the loop should be unrolled fully. The 6706metadata has a single operand which is the string ``llvm.loop.unroll.full``. 6707For example: 6708 6709.. code-block:: llvm 6710 6711 !0 = !{!"llvm.loop.unroll.full"} 6712 6713'``llvm.loop.unroll.followup``' Metadata 6714^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6715 6716This metadata defines which loop attributes the unrolled loop will have. 6717See :ref:`Transformation Metadata <transformation-metadata>` for details. 6718 6719'``llvm.loop.unroll.followup_remainder``' Metadata 6720^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6721 6722This metadata defines which loop attributes the remainder loop after 6723partial/runtime unrolling will have. See 6724:ref:`Transformation Metadata <transformation-metadata>` for details. 6725 6726'``llvm.loop.unroll_and_jam``' 6727^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6728 6729This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata 6730above, but affect the unroll and jam pass. In addition any loop with 6731``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will 6732disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the 6733unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam 6734too.) 6735 6736The metadata for unroll and jam otherwise is the same as for ``unroll``. 6737``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and 6738``llvm.loop.unroll_and_jam.count`` do the same as for unroll. 6739``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints 6740and the normal safety checks will still be performed. 6741 6742'``llvm.loop.unroll_and_jam.count``' Metadata 6743^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6744 6745This metadata suggests an unroll and jam factor to use, similarly to 6746``llvm.loop.unroll.count``. The first operand is the string 6747``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer 6748specifying the unroll factor. For example: 6749 6750.. code-block:: llvm 6751 6752 !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4} 6753 6754If the trip count of the loop is less than the unroll count the loop 6755will be partially unroll and jammed. 6756 6757'``llvm.loop.unroll_and_jam.disable``' Metadata 6758^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6759 6760This metadata disables loop unroll and jamming. The metadata has a single 6761operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example: 6762 6763.. code-block:: llvm 6764 6765 !0 = !{!"llvm.loop.unroll_and_jam.disable"} 6766 6767'``llvm.loop.unroll_and_jam.enable``' Metadata 6768^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6769 6770This metadata suggests that the loop should be fully unroll and jammed if the 6771trip count is known at compile time and partially unrolled if the trip count is 6772not known at compile time. The metadata has a single operand which is the 6773string ``llvm.loop.unroll_and_jam.enable``. For example: 6774 6775.. code-block:: llvm 6776 6777 !0 = !{!"llvm.loop.unroll_and_jam.enable"} 6778 6779'``llvm.loop.unroll_and_jam.followup_outer``' Metadata 6780^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6781 6782This metadata defines which loop attributes the outer unrolled loop will 6783have. See :ref:`Transformation Metadata <transformation-metadata>` for 6784details. 6785 6786'``llvm.loop.unroll_and_jam.followup_inner``' Metadata 6787^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6788 6789This metadata defines which loop attributes the inner jammed loop will 6790have. See :ref:`Transformation Metadata <transformation-metadata>` for 6791details. 6792 6793'``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata 6794^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6795 6796This metadata defines which attributes the epilogue of the outer loop 6797will have. This loop is usually unrolled, meaning there is no such 6798loop. This attribute will be ignored in this case. See 6799:ref:`Transformation Metadata <transformation-metadata>` for details. 6800 6801'``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata 6802^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6803 6804This metadata defines which attributes the inner loop of the epilogue 6805will have. The outer epilogue will usually be unrolled, meaning there 6806can be multiple inner remainder loops. See 6807:ref:`Transformation Metadata <transformation-metadata>` for details. 6808 6809'``llvm.loop.unroll_and_jam.followup_all``' Metadata 6810^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6811 6812Attributes specified in the metadata is added to all 6813``llvm.loop.unroll_and_jam.*`` loops. See 6814:ref:`Transformation Metadata <transformation-metadata>` for details. 6815 6816'``llvm.loop.licm_versioning.disable``' Metadata 6817^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6818 6819This metadata indicates that the loop should not be versioned for the purpose 6820of enabling loop-invariant code motion (LICM). The metadata has a single operand 6821which is the string ``llvm.loop.licm_versioning.disable``. For example: 6822 6823.. code-block:: llvm 6824 6825 !0 = !{!"llvm.loop.licm_versioning.disable"} 6826 6827'``llvm.loop.distribute.enable``' Metadata 6828^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6829 6830Loop distribution allows splitting a loop into multiple loops. Currently, 6831this is only performed if the entire loop cannot be vectorized due to unsafe 6832memory dependencies. The transformation will attempt to isolate the unsafe 6833dependencies into their own loop. 6834 6835This metadata can be used to selectively enable or disable distribution of the 6836loop. The first operand is the string ``llvm.loop.distribute.enable`` and the 6837second operand is a bit. If the bit operand value is 1 distribution is 6838enabled. A value of 0 disables distribution: 6839 6840.. code-block:: llvm 6841 6842 !0 = !{!"llvm.loop.distribute.enable", i1 0} 6843 !1 = !{!"llvm.loop.distribute.enable", i1 1} 6844 6845This metadata should be used in conjunction with ``llvm.loop`` loop 6846identification metadata. 6847 6848'``llvm.loop.distribute.followup_coincident``' Metadata 6849^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6850 6851This metadata defines which attributes extracted loops with no cyclic 6852dependencies will have (i.e. can be vectorized). See 6853:ref:`Transformation Metadata <transformation-metadata>` for details. 6854 6855'``llvm.loop.distribute.followup_sequential``' Metadata 6856^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6857 6858This metadata defines which attributes the isolated loops with unsafe 6859memory dependencies will have. See 6860:ref:`Transformation Metadata <transformation-metadata>` for details. 6861 6862'``llvm.loop.distribute.followup_fallback``' Metadata 6863^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6864 6865If loop versioning is necessary, this metadata defined the attributes 6866the non-distributed fallback version will have. See 6867:ref:`Transformation Metadata <transformation-metadata>` for details. 6868 6869'``llvm.loop.distribute.followup_all``' Metadata 6870^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6871 6872The attributes in this metadata is added to all followup loops of the 6873loop distribution pass. See 6874:ref:`Transformation Metadata <transformation-metadata>` for details. 6875 6876'``llvm.licm.disable``' Metadata 6877^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6878 6879This metadata indicates that loop-invariant code motion (LICM) should not be 6880performed on this loop. The metadata has a single operand which is the string 6881``llvm.licm.disable``. For example: 6882 6883.. code-block:: llvm 6884 6885 !0 = !{!"llvm.licm.disable"} 6886 6887Note that although it operates per loop it isn't given the llvm.loop prefix 6888as it is not affected by the ``llvm.loop.disable_nonforced`` metadata. 6889 6890'``llvm.access.group``' Metadata 6891^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6892 6893``llvm.access.group`` metadata can be attached to any instruction that 6894potentially accesses memory. It can point to a single distinct metadata 6895node, which we call access group. This node represents all memory access 6896instructions referring to it via ``llvm.access.group``. When an 6897instruction belongs to multiple access groups, it can also point to a 6898list of accesses groups, illustrated by the following example. 6899 6900.. code-block:: llvm 6901 6902 %val = load i32, i32* %arrayidx, !llvm.access.group !0 6903 ... 6904 !0 = !{!1, !2} 6905 !1 = distinct !{} 6906 !2 = distinct !{} 6907 6908It is illegal for the list node to be empty since it might be confused 6909with an access group. 6910 6911The access group metadata node must be 'distinct' to avoid collapsing 6912multiple access groups by content. A access group metadata node must 6913always be empty which can be used to distinguish an access group 6914metadata node from a list of access groups. Being empty avoids the 6915situation that the content must be updated which, because metadata is 6916immutable by design, would required finding and updating all references 6917to the access group node. 6918 6919The access group can be used to refer to a memory access instruction 6920without pointing to it directly (which is not possible in global 6921metadata). Currently, the only metadata making use of it is 6922``llvm.loop.parallel_accesses``. 6923 6924'``llvm.loop.parallel_accesses``' Metadata 6925^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6926 6927The ``llvm.loop.parallel_accesses`` metadata refers to one or more 6928access group metadata nodes (see ``llvm.access.group``). It denotes that 6929no loop-carried memory dependence exist between it and other instructions 6930in the loop with this metadata. 6931 6932Let ``m1`` and ``m2`` be two instructions that both have the 6933``llvm.access.group`` metadata to the access group ``g1``, respectively 6934``g2`` (which might be identical). If a loop contains both access groups 6935in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can 6936assume that there is no dependency between ``m1`` and ``m2`` carried by 6937this loop. Instructions that belong to multiple access groups are 6938considered having this property if at least one of the access groups 6939matches the ``llvm.loop.parallel_accesses`` list. 6940 6941If all memory-accessing instructions in a loop have 6942``llvm.access.group`` metadata that each refer to one of the access 6943groups of a loop's ``llvm.loop.parallel_accesses`` metadata, then the 6944loop has no loop carried memory dependences and is considered to be a 6945parallel loop. 6946 6947Note that if not all memory access instructions belong to an access 6948group referred to by ``llvm.loop.parallel_accesses``, then the loop must 6949not be considered trivially parallel. Additional 6950memory dependence analysis is required to make that determination. As a fail 6951safe mechanism, this causes loops that were originally parallel to be considered 6952sequential (if optimization passes that are unaware of the parallel semantics 6953insert new memory instructions into the loop body). 6954 6955Example of a loop that is considered parallel due to its correct use of 6956both ``llvm.access.group`` and ``llvm.loop.parallel_accesses`` 6957metadata types. 6958 6959.. code-block:: llvm 6960 6961 for.body: 6962 ... 6963 %val0 = load i32, i32* %arrayidx, !llvm.access.group !1 6964 ... 6965 store i32 %val0, i32* %arrayidx1, !llvm.access.group !1 6966 ... 6967 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0 6968 6969 for.end: 6970 ... 6971 !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}} 6972 !1 = distinct !{} 6973 6974It is also possible to have nested parallel loops: 6975 6976.. code-block:: llvm 6977 6978 outer.for.body: 6979 ... 6980 %val1 = load i32, i32* %arrayidx3, !llvm.access.group !4 6981 ... 6982 br label %inner.for.body 6983 6984 inner.for.body: 6985 ... 6986 %val0 = load i32, i32* %arrayidx1, !llvm.access.group !3 6987 ... 6988 store i32 %val0, i32* %arrayidx2, !llvm.access.group !3 6989 ... 6990 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1 6991 6992 inner.for.end: 6993 ... 6994 store i32 %val1, i32* %arrayidx4, !llvm.access.group !4 6995 ... 6996 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2 6997 6998 outer.for.end: ; preds = %for.body 6999 ... 7000 !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop 7001 !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop 7002 !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well) 7003 !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop 7004 7005.. _langref_llvm_loop_mustprogress: 7006 7007'``llvm.loop.mustprogress``' Metadata 7008^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7009 7010The ``llvm.loop.mustprogress`` metadata indicates that this loop is required to 7011terminate, unwind, or interact with the environment in an observable way e.g. 7012via a volatile memory access, I/O, or other synchronization. If such a loop is 7013not found to interact with the environment in an observable way, the loop may 7014be removed. This corresponds to the ``mustprogress`` function attribute. 7015 7016'``irr_loop``' Metadata 7017^^^^^^^^^^^^^^^^^^^^^^^ 7018 7019``irr_loop`` metadata may be attached to the terminator instruction of a basic 7020block that's an irreducible loop header (note that an irreducible loop has more 7021than once header basic blocks.) If ``irr_loop`` metadata is attached to the 7022terminator instruction of a basic block that is not really an irreducible loop 7023header, the behavior is undefined. The intent of this metadata is to improve the 7024accuracy of the block frequency propagation. For example, in the code below, the 7025block ``header0`` may have a loop header weight (relative to the other headers of 7026the irreducible loop) of 100: 7027 7028.. code-block:: llvm 7029 7030 header0: 7031 ... 7032 br i1 %cmp, label %t1, label %t2, !irr_loop !0 7033 7034 ... 7035 !0 = !{"loop_header_weight", i64 100} 7036 7037Irreducible loop header weights are typically based on profile data. 7038 7039.. _md_invariant.group: 7040 7041'``invariant.group``' Metadata 7042^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7043 7044The experimental ``invariant.group`` metadata may be attached to 7045``load``/``store`` instructions referencing a single metadata with no entries. 7046The existence of the ``invariant.group`` metadata on the instruction tells 7047the optimizer that every ``load`` and ``store`` to the same pointer operand 7048can be assumed to load or store the same 7049value (but see the ``llvm.launder.invariant.group`` intrinsic which affects 7050when two pointers are considered the same). Pointers returned by bitcast or 7051getelementptr with only zero indices are considered the same. 7052 7053Examples: 7054 7055.. code-block:: llvm 7056 7057 @unknownPtr = external global i8 7058 ... 7059 %ptr = alloca i8 7060 store i8 42, i8* %ptr, !invariant.group !0 7061 call void @foo(i8* %ptr) 7062 7063 %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change 7064 call void @foo(i8* %ptr) 7065 7066 %newPtr = call i8* @getPointer(i8* %ptr) 7067 %c = load i8, i8* %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr 7068 7069 %unknownValue = load i8, i8* @unknownPtr 7070 store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42 7071 7072 call void @foo(i8* %ptr) 7073 %newPtr2 = call i8* @llvm.launder.invariant.group(i8* %ptr) 7074 %d = load i8, i8* %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr 7075 7076 ... 7077 declare void @foo(i8*) 7078 declare i8* @getPointer(i8*) 7079 declare i8* @llvm.launder.invariant.group(i8*) 7080 7081 !0 = !{} 7082 7083The invariant.group metadata must be dropped when replacing one pointer by 7084another based on aliasing information. This is because invariant.group is tied 7085to the SSA value of the pointer operand. 7086 7087.. code-block:: llvm 7088 7089 %v = load i8, i8* %x, !invariant.group !0 7090 ; if %x mustalias %y then we can replace the above instruction with 7091 %v = load i8, i8* %y 7092 7093Note that this is an experimental feature, which means that its semantics might 7094change in the future. 7095 7096'``type``' Metadata 7097^^^^^^^^^^^^^^^^^^^ 7098 7099See :doc:`TypeMetadata`. 7100 7101'``associated``' Metadata 7102^^^^^^^^^^^^^^^^^^^^^^^^^ 7103 7104The ``associated`` metadata may be attached to a global variable definition with 7105a single argument that references a global object (optionally through an alias). 7106 7107This metadata lowers to the ELF section flag ``SHF_LINK_ORDER`` which prevents 7108discarding of the global variable in linker GC unless the referenced object is 7109also discarded. The linker support for this feature is spotty. For best 7110compatibility, globals carrying this metadata should: 7111 7112- Be in ``@llvm.compiler.used``. 7113- If the referenced global variable is in a comdat, be in the same comdat. 7114 7115``!associated`` can not express many-to-one relationship. A global variable with 7116the metadata should generally not be referenced by a function: the function may 7117be inlined into other functions, leading to more references to the metadata. 7118Ideally we would want to keep metadata alive as long as any inline location is 7119alive, but this many-to-one relationship is not representable. Moreover, if the 7120metadata is retained while the function is discarded, the linker will report an 7121error of a relocation referencing a discarded section. 7122 7123The metadata is often used with an explicit section consisting of valid C 7124identifiers so that the runtime can find the metadata section with 7125linker-defined encapsulation symbols ``__start_<section_name>`` and 7126``__stop_<section_name>``. 7127 7128It does not have any effect on non-ELF targets. 7129 7130Example: 7131 7132.. code-block:: text 7133 7134 $a = comdat any 7135 @a = global i32 1, comdat $a 7136 @b = internal global i32 2, comdat $a, section "abc", !associated !0 7137 !0 = !{i32* @a} 7138 7139 7140'``prof``' Metadata 7141^^^^^^^^^^^^^^^^^^^ 7142 7143The ``prof`` metadata is used to record profile data in the IR. 7144The first operand of the metadata node indicates the profile metadata 7145type. There are currently 3 types: 7146:ref:`branch_weights<prof_node_branch_weights>`, 7147:ref:`function_entry_count<prof_node_function_entry_count>`, and 7148:ref:`VP<prof_node_VP>`. 7149 7150.. _prof_node_branch_weights: 7151 7152branch_weights 7153"""""""""""""" 7154 7155Branch weight metadata attached to a branch, select, switch or call instruction 7156represents the likeliness of the associated branch being taken. 7157For more information, see :doc:`BranchWeightMetadata`. 7158 7159.. _prof_node_function_entry_count: 7160 7161function_entry_count 7162"""""""""""""""""""" 7163 7164Function entry count metadata can be attached to function definitions 7165to record the number of times the function is called. Used with BFI 7166information, it is also used to derive the basic block profile count. 7167For more information, see :doc:`BranchWeightMetadata`. 7168 7169.. _prof_node_VP: 7170 7171VP 7172"" 7173 7174VP (value profile) metadata can be attached to instructions that have 7175value profile information. Currently this is indirect calls (where it 7176records the hottest callees) and calls to memory intrinsics such as memcpy, 7177memmove, and memset (where it records the hottest byte lengths). 7178 7179Each VP metadata node contains "VP" string, then a uint32_t value for the value 7180profiling kind, a uint64_t value for the total number of times the instruction 7181is executed, followed by uint64_t value and execution count pairs. 7182The value profiling kind is 0 for indirect call targets and 1 for memory 7183operations. For indirect call targets, each profile value is a hash 7184of the callee function name, and for memory operations each value is the 7185byte length. 7186 7187Note that the value counts do not need to add up to the total count 7188listed in the third operand (in practice only the top hottest values 7189are tracked and reported). 7190 7191Indirect call example: 7192 7193.. code-block:: llvm 7194 7195 call void %f(), !prof !1 7196 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410} 7197 7198Note that the VP type is 0 (the second operand), which indicates this is 7199an indirect call value profile data. The third operand indicates that the 7200indirect call executed 1600 times. The 4th and 6th operands give the 7201hashes of the 2 hottest target functions' names (this is the same hash used 7202to represent function names in the profile database), and the 5th and 7th 7203operands give the execution count that each of the respective prior target 7204functions was called. 7205 7206.. _md_annotation: 7207 7208'``annotation``' Metadata 7209^^^^^^^^^^^^^^^^^^^^^^^^^ 7210 7211The ``annotation`` metadata can be used to attach a tuple of annotation strings 7212to any instruction. This metadata does not impact the semantics of the program 7213and may only be used to provide additional insight about the program and 7214transformations to users. 7215 7216Example: 7217 7218.. code-block:: text 7219 7220 %a.addr = alloca float*, align 8, !annotation !0 7221 !0 = !{!"auto-init"} 7222 7223'``func_sanitize``' Metadata 7224^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7225 7226The ``func_sanitize`` metadata is used to attach two values for the function 7227sanitizer instrumentation. The first value is the ubsan function signature. 7228The second value is the address of the proxy variable which stores the address 7229of the RTTI descriptor. If :ref:`prologue <prologuedata>` and '``func_sanitize``' 7230are used at the same time, :ref:`prologue <prologuedata>` is emitted before 7231'``func_sanitize``' in the output. 7232 7233Example: 7234 7235.. code-block:: text 7236 7237 @__llvm_rtti_proxy = private unnamed_addr constant i8* bitcast ({ i8*, i8* }* @_ZTIFvvE to i8*) 7238 define void @_Z3funv() !func_sanitize !0 { 7239 return void 7240 } 7241 !0 = !{i32 846595819, i8** @__llvm_rtti_proxy} 7242 7243Module Flags Metadata 7244===================== 7245 7246Information about the module as a whole is difficult to convey to LLVM's 7247subsystems. The LLVM IR isn't sufficient to transmit this information. 7248The ``llvm.module.flags`` named metadata exists in order to facilitate 7249this. These flags are in the form of key / value pairs --- much like a 7250dictionary --- making it easy for any subsystem who cares about a flag to 7251look it up. 7252 7253The ``llvm.module.flags`` metadata contains a list of metadata triplets. 7254Each triplet has the following form: 7255 7256- The first element is a *behavior* flag, which specifies the behavior 7257 when two (or more) modules are merged together, and it encounters two 7258 (or more) metadata with the same ID. The supported behaviors are 7259 described below. 7260- The second element is a metadata string that is a unique ID for the 7261 metadata. Each module may only have one flag entry for each unique ID (not 7262 including entries with the **Require** behavior). 7263- The third element is the value of the flag. 7264 7265When two (or more) modules are merged together, the resulting 7266``llvm.module.flags`` metadata is the union of the modules' flags. That is, for 7267each unique metadata ID string, there will be exactly one entry in the merged 7268modules ``llvm.module.flags`` metadata table, and the value for that entry will 7269be determined by the merge behavior flag, as described below. The only exception 7270is that entries with the *Require* behavior are always preserved. 7271 7272The following behaviors are supported: 7273 7274.. list-table:: 7275 :header-rows: 1 7276 :widths: 10 90 7277 7278 * - Value 7279 - Behavior 7280 7281 * - 1 7282 - **Error** 7283 Emits an error if two values disagree, otherwise the resulting value 7284 is that of the operands. 7285 7286 * - 2 7287 - **Warning** 7288 Emits a warning if two values disagree. The result value will be the 7289 operand for the flag from the first module being linked, or the max 7290 if the other module uses **Max** (in which case the resulting flag 7291 will be **Max**). 7292 7293 * - 3 7294 - **Require** 7295 Adds a requirement that another module flag be present and have a 7296 specified value after linking is performed. The value must be a 7297 metadata pair, where the first element of the pair is the ID of the 7298 module flag to be restricted, and the second element of the pair is 7299 the value the module flag should be restricted to. This behavior can 7300 be used to restrict the allowable results (via triggering of an 7301 error) of linking IDs with the **Override** behavior. 7302 7303 * - 4 7304 - **Override** 7305 Uses the specified value, regardless of the behavior or value of the 7306 other module. If both modules specify **Override**, but the values 7307 differ, an error will be emitted. 7308 7309 * - 5 7310 - **Append** 7311 Appends the two values, which are required to be metadata nodes. 7312 7313 * - 6 7314 - **AppendUnique** 7315 Appends the two values, which are required to be metadata 7316 nodes. However, duplicate entries in the second list are dropped 7317 during the append operation. 7318 7319 * - 7 7320 - **Max** 7321 Takes the max of the two values, which are required to be integers. 7322 7323 * - 8 7324 - **Min** 7325 Takes the min of the two values, which are required to be non-negative integers. 7326 An absent module flag is treated as having the value 0. 7327 7328It is an error for a particular unique flag ID to have multiple behaviors, 7329except in the case of **Require** (which adds restrictions on another metadata 7330value) or **Override**. 7331 7332An example of module flags: 7333 7334.. code-block:: llvm 7335 7336 !0 = !{ i32 1, !"foo", i32 1 } 7337 !1 = !{ i32 4, !"bar", i32 37 } 7338 !2 = !{ i32 2, !"qux", i32 42 } 7339 !3 = !{ i32 3, !"qux", 7340 !{ 7341 !"foo", i32 1 7342 } 7343 } 7344 !llvm.module.flags = !{ !0, !1, !2, !3 } 7345 7346- Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior 7347 if two or more ``!"foo"`` flags are seen is to emit an error if their 7348 values are not equal. 7349 7350- Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The 7351 behavior if two or more ``!"bar"`` flags are seen is to use the value 7352 '37'. 7353 7354- Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The 7355 behavior if two or more ``!"qux"`` flags are seen is to emit a 7356 warning if their values are not equal. 7357 7358- Metadata ``!3`` has the ID ``!"qux"`` and the value: 7359 7360 :: 7361 7362 !{ !"foo", i32 1 } 7363 7364 The behavior is to emit an error if the ``llvm.module.flags`` does not 7365 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is 7366 performed. 7367 7368Synthesized Functions Module Flags Metadata 7369------------------------------------------- 7370 7371These metadata specify the default attributes synthesized functions should have. 7372These metadata are currently respected by a few instrumentation passes, such as 7373sanitizers. 7374 7375These metadata correspond to a few function attributes with significant code 7376generation behaviors. Function attributes with just optimization purposes 7377should not be listed because the performance impact of these synthesized 7378functions is small. 7379 7380- "frame-pointer": **Max**. The value can be 0, 1, or 2. A synthesized function 7381 will get the "frame-pointer" function attribute, with value being "none", 7382 "non-leaf", or "all", respectively. 7383- "function_return_thunk_extern": The synthesized function will get the 7384 ``fn_return_thunk_extern`` function attribute. 7385- "uwtable": **Max**. The value can be 0, 1, or 2. If the value is 1, a synthesized 7386 function will get the ``uwtable(sync)`` function attribute, if the value is 2, 7387 a synthesized function will get the ``uwtable(async)`` function attribute. 7388 7389Objective-C Garbage Collection Module Flags Metadata 7390---------------------------------------------------- 7391 7392On the Mach-O platform, Objective-C stores metadata about garbage 7393collection in a special section called "image info". The metadata 7394consists of a version number and a bitmask specifying what types of 7395garbage collection are supported (if any) by the file. If two or more 7396modules are linked together their garbage collection metadata needs to 7397be merged rather than appended together. 7398 7399The Objective-C garbage collection module flags metadata consists of the 7400following key-value pairs: 7401 7402.. list-table:: 7403 :header-rows: 1 7404 :widths: 30 70 7405 7406 * - Key 7407 - Value 7408 7409 * - ``Objective-C Version`` 7410 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2. 7411 7412 * - ``Objective-C Image Info Version`` 7413 - **[Required]** --- The version of the image info section. Currently 7414 always 0. 7415 7416 * - ``Objective-C Image Info Section`` 7417 - **[Required]** --- The section to place the metadata. Valid values are 7418 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and 7419 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for 7420 Objective-C ABI version 2. 7421 7422 * - ``Objective-C Garbage Collection`` 7423 - **[Required]** --- Specifies whether garbage collection is supported or 7424 not. Valid values are 0, for no garbage collection, and 2, for garbage 7425 collection supported. 7426 7427 * - ``Objective-C GC Only`` 7428 - **[Optional]** --- Specifies that only garbage collection is supported. 7429 If present, its value must be 6. This flag requires that the 7430 ``Objective-C Garbage Collection`` flag have the value 2. 7431 7432Some important flag interactions: 7433 7434- If a module with ``Objective-C Garbage Collection`` set to 0 is 7435 merged with a module with ``Objective-C Garbage Collection`` set to 7436 2, then the resulting module has the 7437 ``Objective-C Garbage Collection`` flag set to 0. 7438- A module with ``Objective-C Garbage Collection`` set to 0 cannot be 7439 merged with a module with ``Objective-C GC Only`` set to 6. 7440 7441C type width Module Flags Metadata 7442---------------------------------- 7443 7444The ARM backend emits a section into each generated object file describing the 7445options that it was compiled with (in a compiler-independent way) to prevent 7446linking incompatible objects, and to allow automatic library selection. Some 7447of these options are not visible at the IR level, namely wchar_t width and enum 7448width. 7449 7450To pass this information to the backend, these options are encoded in module 7451flags metadata, using the following key-value pairs: 7452 7453.. list-table:: 7454 :header-rows: 1 7455 :widths: 30 70 7456 7457 * - Key 7458 - Value 7459 7460 * - short_wchar 7461 - * 0 --- sizeof(wchar_t) == 4 7462 * 1 --- sizeof(wchar_t) == 2 7463 7464 * - short_enum 7465 - * 0 --- Enums are at least as large as an ``int``. 7466 * 1 --- Enums are stored in the smallest integer type which can 7467 represent all of its values. 7468 7469For example, the following metadata section specifies that the module was 7470compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an 7471enum is the smallest type which can represent all of its values:: 7472 7473 !llvm.module.flags = !{!0, !1} 7474 !0 = !{i32 1, !"short_wchar", i32 1} 7475 !1 = !{i32 1, !"short_enum", i32 0} 7476 7477LTO Post-Link Module Flags Metadata 7478----------------------------------- 7479 7480Some optimisations are only when the entire LTO unit is present in the current 7481module. This is represented by the ``LTOPostLink`` module flags metadata, which 7482will be created with a value of ``1`` when LTO linking occurs. 7483 7484Embedded Objects Names Metadata 7485=============================== 7486 7487Offloading compilations need to embed device code into the host section table to 7488create a fat binary. This metadata node references each global that will be 7489embedded in the module. The primary use for this is to make referencing these 7490globals more efficient in the IR. The metadata references nodes containing 7491pointers to the global to be embedded followed by the section name it will be 7492stored at:: 7493 7494 !llvm.embedded.objects = !{!0} 7495 !0 = !{ptr @object, !".section"} 7496 7497Automatic Linker Flags Named Metadata 7498===================================== 7499 7500Some targets support embedding of flags to the linker inside individual object 7501files. Typically this is used in conjunction with language extensions which 7502allow source files to contain linker command line options, and have these 7503automatically be transmitted to the linker via object files. 7504 7505These flags are encoded in the IR using named metadata with the name 7506``!llvm.linker.options``. Each operand is expected to be a metadata node 7507which should be a list of other metadata nodes, each of which should be a 7508list of metadata strings defining linker options. 7509 7510For example, the following metadata section specifies two separate sets of 7511linker options, presumably to link against ``libz`` and the ``Cocoa`` 7512framework:: 7513 7514 !0 = !{ !"-lz" } 7515 !1 = !{ !"-framework", !"Cocoa" } 7516 !llvm.linker.options = !{ !0, !1 } 7517 7518The metadata encoding as lists of lists of options, as opposed to a collapsed 7519list of options, is chosen so that the IR encoding can use multiple option 7520strings to specify e.g., a single library, while still having that specifier be 7521preserved as an atomic element that can be recognized by a target specific 7522assembly writer or object file emitter. 7523 7524Each individual option is required to be either a valid option for the target's 7525linker, or an option that is reserved by the target specific assembly writer or 7526object file emitter. No other aspect of these options is defined by the IR. 7527 7528Dependent Libs Named Metadata 7529============================= 7530 7531Some targets support embedding of strings into object files to indicate 7532a set of libraries to add to the link. Typically this is used in conjunction 7533with language extensions which allow source files to explicitly declare the 7534libraries they depend on, and have these automatically be transmitted to the 7535linker via object files. 7536 7537The list is encoded in the IR using named metadata with the name 7538``!llvm.dependent-libraries``. Each operand is expected to be a metadata node 7539which should contain a single string operand. 7540 7541For example, the following metadata section contains two library specifiers:: 7542 7543 !0 = !{!"a library specifier"} 7544 !1 = !{!"another library specifier"} 7545 !llvm.dependent-libraries = !{ !0, !1 } 7546 7547Each library specifier will be handled independently by the consuming linker. 7548The effect of the library specifiers are defined by the consuming linker. 7549 7550.. _summary: 7551 7552ThinLTO Summary 7553=============== 7554 7555Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_ 7556causes the building of a compact summary of the module that is emitted into 7557the bitcode. The summary is emitted into the LLVM assembly and identified 7558in syntax by a caret ('``^``'). 7559 7560The summary is parsed into a bitcode output, along with the Module 7561IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes 7562of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the 7563summary entries (just as they currently ignore summary entries in a bitcode 7564input file). 7565 7566Eventually, the summary will be parsed into a ModuleSummaryIndex object under 7567the same conditions where summary index is currently built from bitcode. 7568Specifically, tools that test the Thin Link portion of a ThinLTO compile 7569(i.e. llvm-lto and llvm-lto2), or when parsing a combined index 7570for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag 7571(this part is not yet implemented, use llvm-as to create a bitcode object 7572before feeding into thin link tools for now). 7573 7574There are currently 3 types of summary entries in the LLVM assembly: 7575:ref:`module paths<module_path_summary>`, 7576:ref:`global values<gv_summary>`, and 7577:ref:`type identifiers<typeid_summary>`. 7578 7579.. _module_path_summary: 7580 7581Module Path Summary Entry 7582------------------------- 7583 7584Each module path summary entry lists a module containing global values included 7585in the summary. For a single IR module there will be one such entry, but 7586in a combined summary index produced during the thin link, there will be 7587one module path entry per linked module with summary. 7588 7589Example: 7590 7591.. code-block:: text 7592 7593 ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418)) 7594 7595The ``path`` field is a string path to the bitcode file, and the ``hash`` 7596field is the 160-bit SHA-1 hash of the IR bitcode contents, used for 7597incremental builds and caching. 7598 7599.. _gv_summary: 7600 7601Global Value Summary Entry 7602-------------------------- 7603 7604Each global value summary entry corresponds to a global value defined or 7605referenced by a summarized module. 7606 7607Example: 7608 7609.. code-block:: text 7610 7611 ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831 7612 7613For declarations, there will not be a summary list. For definitions, a 7614global value will contain a list of summaries, one per module containing 7615a definition. There can be multiple entries in a combined summary index 7616for symbols with weak linkage. 7617 7618Each ``Summary`` format will depend on whether the global value is a 7619:ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or 7620:ref:`alias<alias_summary>`. 7621 7622.. _function_summary: 7623 7624Function Summary 7625^^^^^^^^^^^^^^^^ 7626 7627If the global value is a function, the ``Summary`` entry will look like: 7628 7629.. code-block:: text 7630 7631 function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Params]?[, Refs]? 7632 7633The ``module`` field includes the summary entry id for the module containing 7634this definition, and the ``flags`` field contains information such as 7635the linkage type, a flag indicating whether it is legal to import the 7636definition, whether it is globally live and whether the linker resolved it 7637to a local definition (the latter two are populated during the thin link). 7638The ``insts`` field contains the number of IR instructions in the function. 7639Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`, 7640:ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`, 7641:ref:`Params<params_summary>`, :ref:`Refs<refs_summary>`. 7642 7643.. _variable_summary: 7644 7645Global Variable Summary 7646^^^^^^^^^^^^^^^^^^^^^^^ 7647 7648If the global value is a variable, the ``Summary`` entry will look like: 7649 7650.. code-block:: text 7651 7652 variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]? 7653 7654The variable entry contains a subset of the fields in a 7655:ref:`function summary <function_summary>`, see the descriptions there. 7656 7657.. _alias_summary: 7658 7659Alias Summary 7660^^^^^^^^^^^^^ 7661 7662If the global value is an alias, the ``Summary`` entry will look like: 7663 7664.. code-block:: text 7665 7666 alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2) 7667 7668The ``module`` and ``flags`` fields are as described for a 7669:ref:`function summary <function_summary>`. The ``aliasee`` field 7670contains a reference to the global value summary entry of the aliasee. 7671 7672.. _funcflags_summary: 7673 7674Function Flags 7675^^^^^^^^^^^^^^ 7676 7677The optional ``FuncFlags`` field looks like: 7678 7679.. code-block:: text 7680 7681 funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0, noUnwind: 1, mayThrow: 0, hasUnknownCall: 0) 7682 7683If unspecified, flags are assumed to hold the conservative ``false`` value of 7684``0``. 7685 7686.. _calls_summary: 7687 7688Calls 7689^^^^^ 7690 7691The optional ``Calls`` field looks like: 7692 7693.. code-block:: text 7694 7695 calls: ((Callee)[, (Callee)]*) 7696 7697where each ``Callee`` looks like: 7698 7699.. code-block:: text 7700 7701 callee: ^1[, hotness: None]?[, relbf: 0]? 7702 7703The ``callee`` refers to the summary entry id of the callee. At most one 7704of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``, 7705``Hot``, and ``Critical``), and ``relbf`` (which holds the integer 7706branch frequency relative to the entry frequency, scaled down by 2^8) 7707may be specified. The defaults are ``Unknown`` and ``0``, respectively. 7708 7709.. _params_summary: 7710 7711Params 7712^^^^^^ 7713 7714The optional ``Params`` is used by ``StackSafety`` and looks like: 7715 7716.. code-block:: text 7717 7718 Params: ((Param)[, (Param)]*) 7719 7720where each ``Param`` describes pointer parameter access inside of the 7721function and looks like: 7722 7723.. code-block:: text 7724 7725 param: 4, offset: [0, 5][, calls: ((Callee)[, (Callee)]*)]? 7726 7727where the first ``param`` is the number of the parameter it describes, 7728``offset`` is the inclusive range of offsets from the pointer parameter to bytes 7729which can be accessed by the function. This range does not include accesses by 7730function calls from ``calls`` list. 7731 7732where each ``Callee`` describes how parameter is forwarded into other 7733functions and looks like: 7734 7735.. code-block:: text 7736 7737 callee: ^3, param: 5, offset: [-3, 3] 7738 7739The ``callee`` refers to the summary entry id of the callee, ``param`` is 7740the number of the callee parameter which points into the callers parameter 7741with offset known to be inside of the ``offset`` range. ``calls`` will be 7742consumed and removed by thin link stage to update ``Param::offset`` so it 7743covers all accesses possible by ``calls``. 7744 7745Pointer parameter without corresponding ``Param`` is considered unsafe and we 7746assume that access with any offset is possible. 7747 7748Example: 7749 7750If we have the following function: 7751 7752.. code-block:: text 7753 7754 define i64 @foo(i64* %0, i32* %1, i8* %2, i8 %3) { 7755 store i32* %1, i32** @x 7756 %5 = getelementptr inbounds i8, i8* %2, i64 5 7757 %6 = load i8, i8* %5 7758 %7 = getelementptr inbounds i8, i8* %2, i8 %3 7759 tail call void @bar(i8 %3, i8* %7) 7760 %8 = load i64, i64* %0 7761 ret i64 %8 7762 } 7763 7764We can expect the record like this: 7765 7766.. code-block:: text 7767 7768 params: ((param: 0, offset: [0, 7]),(param: 2, offset: [5, 5], calls: ((callee: ^3, param: 1, offset: [-128, 127])))) 7769 7770The function may access just 8 bytes of the parameter %0 . ``calls`` is empty, 7771so the parameter is either not used for function calls or ``offset`` already 7772covers all accesses from nested function calls. 7773Parameter %1 escapes, so access is unknown. 7774The function itself can access just a single byte of the parameter %2. Additional 7775access is possible inside of the ``@bar`` or ``^3``. The function adds signed 7776offset to the pointer and passes the result as the argument %1 into ``^3``. 7777This record itself does not tell us how ``^3`` will access the parameter. 7778Parameter %3 is not a pointer. 7779 7780.. _refs_summary: 7781 7782Refs 7783^^^^ 7784 7785The optional ``Refs`` field looks like: 7786 7787.. code-block:: text 7788 7789 refs: ((Ref)[, (Ref)]*) 7790 7791where each ``Ref`` contains a reference to the summary id of the referenced 7792value (e.g. ``^1``). 7793 7794.. _typeidinfo_summary: 7795 7796TypeIdInfo 7797^^^^^^^^^^ 7798 7799The optional ``TypeIdInfo`` field, used for 7800`Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, 7801looks like: 7802 7803.. code-block:: text 7804 7805 typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]? 7806 7807These optional fields have the following forms: 7808 7809TypeTests 7810""""""""" 7811 7812.. code-block:: text 7813 7814 typeTests: (TypeIdRef[, TypeIdRef]*) 7815 7816Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>` 7817by summary id or ``GUID``. 7818 7819TypeTestAssumeVCalls 7820"""""""""""""""""""" 7821 7822.. code-block:: text 7823 7824 typeTestAssumeVCalls: (VFuncId[, VFuncId]*) 7825 7826Where each VFuncId has the format: 7827 7828.. code-block:: text 7829 7830 vFuncId: (TypeIdRef, offset: 16) 7831 7832Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>` 7833by summary id or ``GUID`` preceded by a ``guid:`` tag. 7834 7835TypeCheckedLoadVCalls 7836""""""""""""""""""""" 7837 7838.. code-block:: text 7839 7840 typeCheckedLoadVCalls: (VFuncId[, VFuncId]*) 7841 7842Where each VFuncId has the format described for ``TypeTestAssumeVCalls``. 7843 7844TypeTestAssumeConstVCalls 7845""""""""""""""""""""""""" 7846 7847.. code-block:: text 7848 7849 typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*) 7850 7851Where each ConstVCall has the format: 7852 7853.. code-block:: text 7854 7855 (VFuncId, args: (Arg[, Arg]*)) 7856 7857and where each VFuncId has the format described for ``TypeTestAssumeVCalls``, 7858and each Arg is an integer argument number. 7859 7860TypeCheckedLoadConstVCalls 7861"""""""""""""""""""""""""" 7862 7863.. code-block:: text 7864 7865 typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*) 7866 7867Where each ConstVCall has the format described for 7868``TypeTestAssumeConstVCalls``. 7869 7870.. _typeid_summary: 7871 7872Type ID Summary Entry 7873--------------------- 7874 7875Each type id summary entry corresponds to a type identifier resolution 7876which is generated during the LTO link portion of the compile when building 7877with `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, 7878so these are only present in a combined summary index. 7879 7880Example: 7881 7882.. code-block:: text 7883 7884 ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778 7885 7886The ``typeTestRes`` gives the type test resolution ``kind`` (which may 7887be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and 7888the ``size-1`` bit width. It is followed by optional flags, which default to 0, 7889and an optional WpdResolutions (whole program devirtualization resolution) 7890field that looks like: 7891 7892.. code-block:: text 7893 7894 wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]* 7895 7896where each entry is a mapping from the given byte offset to the whole-program 7897devirtualization resolution WpdRes, that has one of the following formats: 7898 7899.. code-block:: text 7900 7901 wpdRes: (kind: branchFunnel) 7902 wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi") 7903 wpdRes: (kind: indir) 7904 7905Additionally, each wpdRes has an optional ``resByArg`` field, which 7906describes the resolutions for calls with all constant integer arguments: 7907 7908.. code-block:: text 7909 7910 resByArg: (ResByArg[, ResByArg]*) 7911 7912where ResByArg is: 7913 7914.. code-block:: text 7915 7916 args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0]) 7917 7918Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal`` 7919or ``VirtualConstProp``. The ``info`` field is only used if the kind 7920is ``UniformRetVal`` (indicates the uniform return value), or 7921``UniqueRetVal`` (holds the return value associated with the unique vtable 7922(0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does 7923not support the use of absolute symbols to store constants. 7924 7925.. _intrinsicglobalvariables: 7926 7927Intrinsic Global Variables 7928========================== 7929 7930LLVM has a number of "magic" global variables that contain data that 7931affect code generation or other IR semantics. These are documented here. 7932All globals of this sort should have a section specified as 7933"``llvm.metadata``". This section and all globals that start with 7934"``llvm.``" are reserved for use by LLVM. 7935 7936.. _gv_llvmused: 7937 7938The '``llvm.used``' Global Variable 7939----------------------------------- 7940 7941The ``@llvm.used`` global is an array which has 7942:ref:`appending linkage <linkage_appending>`. This array contains a list of 7943pointers to named global variables, functions and aliases which may optionally 7944have a pointer cast formed of bitcast or getelementptr. For example, a legal 7945use of it is: 7946 7947.. code-block:: llvm 7948 7949 @X = global i8 4 7950 @Y = global i32 123 7951 7952 @llvm.used = appending global [2 x i8*] [ 7953 i8* @X, 7954 i8* bitcast (i32* @Y to i8*) 7955 ], section "llvm.metadata" 7956 7957If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler, 7958and linker are required to treat the symbol as if there is a reference to the 7959symbol that it cannot see (which is why they have to be named). For example, if 7960a variable has internal linkage and no references other than that from the 7961``@llvm.used`` list, it cannot be deleted. This is commonly used to represent 7962references from inline asms and other things the compiler cannot "see", and 7963corresponds to "``attribute((used))``" in GNU C. 7964 7965On some targets, the code generator must emit a directive to the 7966assembler or object file to prevent the assembler and linker from 7967removing the symbol. 7968 7969.. _gv_llvmcompilerused: 7970 7971The '``llvm.compiler.used``' Global Variable 7972-------------------------------------------- 7973 7974The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used`` 7975directive, except that it only prevents the compiler from touching the 7976symbol. On targets that support it, this allows an intelligent linker to 7977optimize references to the symbol without being impeded as it would be 7978by ``@llvm.used``. 7979 7980This is a rare construct that should only be used in rare circumstances, 7981and should not be exposed to source languages. 7982 7983.. _gv_llvmglobalctors: 7984 7985The '``llvm.global_ctors``' Global Variable 7986------------------------------------------- 7987 7988.. code-block:: llvm 7989 7990 %0 = type { i32, void ()*, i8* } 7991 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }] 7992 7993The ``@llvm.global_ctors`` array contains a list of constructor 7994functions, priorities, and an associated global or function. 7995The functions referenced by this array will be called in ascending order 7996of priority (i.e. lowest first) when the module is loaded. The order of 7997functions with the same priority is not defined. 7998 7999If the third field is non-null, and points to a global variable 8000or function, the initializer function will only run if the associated 8001data from the current module is not discarded. 8002On ELF the referenced global variable or function must be in a comdat. 8003 8004.. _llvmglobaldtors: 8005 8006The '``llvm.global_dtors``' Global Variable 8007------------------------------------------- 8008 8009.. code-block:: llvm 8010 8011 %0 = type { i32, void ()*, i8* } 8012 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }] 8013 8014The ``@llvm.global_dtors`` array contains a list of destructor 8015functions, priorities, and an associated global or function. 8016The functions referenced by this array will be called in descending 8017order of priority (i.e. highest first) when the module is unloaded. The 8018order of functions with the same priority is not defined. 8019 8020If the third field is non-null, and points to a global variable 8021or function, the destructor function will only run if the associated 8022data from the current module is not discarded. 8023On ELF the referenced global variable or function must be in a comdat. 8024 8025Instruction Reference 8026===================== 8027 8028The LLVM instruction set consists of several different classifications 8029of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary 8030instructions <binaryops>`, :ref:`bitwise binary 8031instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and 8032:ref:`other instructions <otherops>`. 8033 8034.. _terminators: 8035 8036Terminator Instructions 8037----------------------- 8038 8039As mentioned :ref:`previously <functionstructure>`, every basic block in a 8040program ends with a "Terminator" instruction, which indicates which 8041block should be executed after the current block is finished. These 8042terminator instructions typically yield a '``void``' value: they produce 8043control flow, not values (the one exception being the 8044':ref:`invoke <i_invoke>`' instruction). 8045 8046The terminator instructions are: ':ref:`ret <i_ret>`', 8047':ref:`br <i_br>`', ':ref:`switch <i_switch>`', 8048':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`', 8049':ref:`callbr <i_callbr>`' 8050':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`', 8051':ref:`catchret <i_catchret>`', 8052':ref:`cleanupret <i_cleanupret>`', 8053and ':ref:`unreachable <i_unreachable>`'. 8054 8055.. _i_ret: 8056 8057'``ret``' Instruction 8058^^^^^^^^^^^^^^^^^^^^^ 8059 8060Syntax: 8061""""""" 8062 8063:: 8064 8065 ret <type> <value> ; Return a value from a non-void function 8066 ret void ; Return from void function 8067 8068Overview: 8069""""""""" 8070 8071The '``ret``' instruction is used to return control flow (and optionally 8072a value) from a function back to the caller. 8073 8074There are two forms of the '``ret``' instruction: one that returns a 8075value and then causes control flow, and one that just causes control 8076flow to occur. 8077 8078Arguments: 8079"""""""""" 8080 8081The '``ret``' instruction optionally accepts a single argument, the 8082return value. The type of the return value must be a ':ref:`first 8083class <t_firstclass>`' type. 8084 8085A function is not :ref:`well formed <wellformed>` if it has a non-void 8086return type and contains a '``ret``' instruction with no return value or 8087a return value with a type that does not match its type, or if it has a 8088void return type and contains a '``ret``' instruction with a return 8089value. 8090 8091Semantics: 8092"""""""""" 8093 8094When the '``ret``' instruction is executed, control flow returns back to 8095the calling function's context. If the caller is a 8096":ref:`call <i_call>`" instruction, execution continues at the 8097instruction after the call. If the caller was an 8098":ref:`invoke <i_invoke>`" instruction, execution continues at the 8099beginning of the "normal" destination block. If the instruction returns 8100a value, that value shall set the call or invoke instruction's return 8101value. 8102 8103Example: 8104"""""""" 8105 8106.. code-block:: llvm 8107 8108 ret i32 5 ; Return an integer value of 5 8109 ret void ; Return from a void function 8110 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2 8111 8112.. _i_br: 8113 8114'``br``' Instruction 8115^^^^^^^^^^^^^^^^^^^^ 8116 8117Syntax: 8118""""""" 8119 8120:: 8121 8122 br i1 <cond>, label <iftrue>, label <iffalse> 8123 br label <dest> ; Unconditional branch 8124 8125Overview: 8126""""""""" 8127 8128The '``br``' instruction is used to cause control flow to transfer to a 8129different basic block in the current function. There are two forms of 8130this instruction, corresponding to a conditional branch and an 8131unconditional branch. 8132 8133Arguments: 8134"""""""""" 8135 8136The conditional branch form of the '``br``' instruction takes a single 8137'``i1``' value and two '``label``' values. The unconditional form of the 8138'``br``' instruction takes a single '``label``' value as a target. 8139 8140Semantics: 8141"""""""""" 8142 8143Upon execution of a conditional '``br``' instruction, the '``i1``' 8144argument is evaluated. If the value is ``true``, control flows to the 8145'``iftrue``' ``label`` argument. If "cond" is ``false``, control flows 8146to the '``iffalse``' ``label`` argument. 8147If '``cond``' is ``poison`` or ``undef``, this instruction has undefined 8148behavior. 8149 8150Example: 8151"""""""" 8152 8153.. code-block:: llvm 8154 8155 Test: 8156 %cond = icmp eq i32 %a, %b 8157 br i1 %cond, label %IfEqual, label %IfUnequal 8158 IfEqual: 8159 ret i32 1 8160 IfUnequal: 8161 ret i32 0 8162 8163.. _i_switch: 8164 8165'``switch``' Instruction 8166^^^^^^^^^^^^^^^^^^^^^^^^ 8167 8168Syntax: 8169""""""" 8170 8171:: 8172 8173 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] 8174 8175Overview: 8176""""""""" 8177 8178The '``switch``' instruction is used to transfer control flow to one of 8179several different places. It is a generalization of the '``br``' 8180instruction, allowing a branch to occur to one of many possible 8181destinations. 8182 8183Arguments: 8184"""""""""" 8185 8186The '``switch``' instruction uses three parameters: an integer 8187comparison value '``value``', a default '``label``' destination, and an 8188array of pairs of comparison value constants and '``label``'s. The table 8189is not allowed to contain duplicate constant entries. 8190 8191Semantics: 8192"""""""""" 8193 8194The ``switch`` instruction specifies a table of values and destinations. 8195When the '``switch``' instruction is executed, this table is searched 8196for the given value. If the value is found, control flow is transferred 8197to the corresponding destination; otherwise, control flow is transferred 8198to the default destination. 8199If '``value``' is ``poison`` or ``undef``, this instruction has undefined 8200behavior. 8201 8202Implementation: 8203""""""""""""""" 8204 8205Depending on properties of the target machine and the particular 8206``switch`` instruction, this instruction may be code generated in 8207different ways. For example, it could be generated as a series of 8208chained conditional branches or with a lookup table. 8209 8210Example: 8211"""""""" 8212 8213.. code-block:: llvm 8214 8215 ; Emulate a conditional br instruction 8216 %Val = zext i1 %value to i32 8217 switch i32 %Val, label %truedest [ i32 0, label %falsedest ] 8218 8219 ; Emulate an unconditional br instruction 8220 switch i32 0, label %dest [ ] 8221 8222 ; Implement a jump table: 8223 switch i32 %val, label %otherwise [ i32 0, label %onzero 8224 i32 1, label %onone 8225 i32 2, label %ontwo ] 8226 8227.. _i_indirectbr: 8228 8229'``indirectbr``' Instruction 8230^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8231 8232Syntax: 8233""""""" 8234 8235:: 8236 8237 indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ] 8238 8239Overview: 8240""""""""" 8241 8242The '``indirectbr``' instruction implements an indirect branch to a 8243label within the current function, whose address is specified by 8244"``address``". Address must be derived from a 8245:ref:`blockaddress <blockaddress>` constant. 8246 8247Arguments: 8248"""""""""" 8249 8250The '``address``' argument is the address of the label to jump to. The 8251rest of the arguments indicate the full set of possible destinations 8252that the address may point to. Blocks are allowed to occur multiple 8253times in the destination list, though this isn't particularly useful. 8254 8255This destination list is required so that dataflow analysis has an 8256accurate understanding of the CFG. 8257 8258Semantics: 8259"""""""""" 8260 8261Control transfers to the block specified in the address argument. All 8262possible destination blocks must be listed in the label list, otherwise 8263this instruction has undefined behavior. This implies that jumps to 8264labels defined in other functions have undefined behavior as well. 8265If '``address``' is ``poison`` or ``undef``, this instruction has undefined 8266behavior. 8267 8268Implementation: 8269""""""""""""""" 8270 8271This is typically implemented with a jump through a register. 8272 8273Example: 8274"""""""" 8275 8276.. code-block:: llvm 8277 8278 indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ] 8279 8280.. _i_invoke: 8281 8282'``invoke``' Instruction 8283^^^^^^^^^^^^^^^^^^^^^^^^ 8284 8285Syntax: 8286""""""" 8287 8288:: 8289 8290 <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 8291 [operand bundles] to label <normal label> unwind label <exception label> 8292 8293Overview: 8294""""""""" 8295 8296The '``invoke``' instruction causes control to transfer to a specified 8297function, with the possibility of control flow transfer to either the 8298'``normal``' label or the '``exception``' label. If the callee function 8299returns with the "``ret``" instruction, control flow will return to the 8300"normal" label. If the callee (or any indirect callees) returns via the 8301":ref:`resume <i_resume>`" instruction or other exception handling 8302mechanism, control is interrupted and continued at the dynamically 8303nearest "exception" label. 8304 8305The '``exception``' label is a `landing 8306pad <ExceptionHandling.html#overview>`_ for the exception. As such, 8307'``exception``' label is required to have the 8308":ref:`landingpad <i_landingpad>`" instruction, which contains the 8309information about the behavior of the program after unwinding happens, 8310as its first non-PHI instruction. The restrictions on the 8311"``landingpad``" instruction's tightly couples it to the "``invoke``" 8312instruction, so that the important information contained within the 8313"``landingpad``" instruction can't be lost through normal code motion. 8314 8315Arguments: 8316"""""""""" 8317 8318This instruction requires several arguments: 8319 8320#. The optional "cconv" marker indicates which :ref:`calling 8321 convention <callingconv>` the call should use. If none is 8322 specified, the call defaults to using C calling conventions. 8323#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 8324 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 8325 are valid here. 8326#. The optional addrspace attribute can be used to indicate the address space 8327 of the called function. If it is not specified, the program address space 8328 from the :ref:`datalayout string<langref_datalayout>` will be used. 8329#. '``ty``': the type of the call instruction itself which is also the 8330 type of the return value. Functions that return no value are marked 8331 ``void``. 8332#. '``fnty``': shall be the signature of the function being invoked. The 8333 argument types must match the types implied by this signature. This 8334 type can be omitted if the function is not varargs. 8335#. '``fnptrval``': An LLVM value containing a pointer to a function to 8336 be invoked. In most cases, this is a direct function invocation, but 8337 indirect ``invoke``'s are just as possible, calling an arbitrary pointer 8338 to function value. 8339#. '``function args``': argument list whose types match the function 8340 signature argument types and parameter attributes. All arguments must 8341 be of :ref:`first class <t_firstclass>` type. If the function signature 8342 indicates the function accepts a variable number of arguments, the 8343 extra arguments can be specified. 8344#. '``normal label``': the label reached when the called function 8345 executes a '``ret``' instruction. 8346#. '``exception label``': the label reached when a callee returns via 8347 the :ref:`resume <i_resume>` instruction or other exception handling 8348 mechanism. 8349#. The optional :ref:`function attributes <fnattrs>` list. 8350#. The optional :ref:`operand bundles <opbundles>` list. 8351 8352Semantics: 8353"""""""""" 8354 8355This instruction is designed to operate as a standard '``call``' 8356instruction in most regards. The primary difference is that it 8357establishes an association with a label, which is used by the runtime 8358library to unwind the stack. 8359 8360This instruction is used in languages with destructors to ensure that 8361proper cleanup is performed in the case of either a ``longjmp`` or a 8362thrown exception. Additionally, this is important for implementation of 8363'``catch``' clauses in high-level languages that support them. 8364 8365For the purposes of the SSA form, the definition of the value returned 8366by the '``invoke``' instruction is deemed to occur on the edge from the 8367current block to the "normal" label. If the callee unwinds then no 8368return value is available. 8369 8370Example: 8371"""""""" 8372 8373.. code-block:: llvm 8374 8375 %retval = invoke i32 @Test(i32 15) to label %Continue 8376 unwind label %TestCleanup ; i32:retval set 8377 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue 8378 unwind label %TestCleanup ; i32:retval set 8379 8380.. _i_callbr: 8381 8382'``callbr``' Instruction 8383^^^^^^^^^^^^^^^^^^^^^^^^ 8384 8385Syntax: 8386""""""" 8387 8388:: 8389 8390 <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 8391 [operand bundles] to label <fallthrough label> [indirect labels] 8392 8393Overview: 8394""""""""" 8395 8396The '``callbr``' instruction causes control to transfer to a specified 8397function, with the possibility of control flow transfer to either the 8398'``fallthrough``' label or one of the '``indirect``' labels. 8399 8400This instruction should only be used to implement the "goto" feature of gcc 8401style inline assembly. Any other usage is an error in the IR verifier. 8402 8403Arguments: 8404"""""""""" 8405 8406This instruction requires several arguments: 8407 8408#. The optional "cconv" marker indicates which :ref:`calling 8409 convention <callingconv>` the call should use. If none is 8410 specified, the call defaults to using C calling conventions. 8411#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 8412 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 8413 are valid here. 8414#. The optional addrspace attribute can be used to indicate the address space 8415 of the called function. If it is not specified, the program address space 8416 from the :ref:`datalayout string<langref_datalayout>` will be used. 8417#. '``ty``': the type of the call instruction itself which is also the 8418 type of the return value. Functions that return no value are marked 8419 ``void``. 8420#. '``fnty``': shall be the signature of the function being called. The 8421 argument types must match the types implied by this signature. This 8422 type can be omitted if the function is not varargs. 8423#. '``fnptrval``': An LLVM value containing a pointer to a function to 8424 be called. In most cases, this is a direct function call, but 8425 other ``callbr``'s are just as possible, calling an arbitrary pointer 8426 to function value. 8427#. '``function args``': argument list whose types match the function 8428 signature argument types and parameter attributes. All arguments must 8429 be of :ref:`first class <t_firstclass>` type. If the function signature 8430 indicates the function accepts a variable number of arguments, the 8431 extra arguments can be specified. 8432#. '``fallthrough label``': the label reached when the inline assembly's 8433 execution exits the bottom. 8434#. '``indirect labels``': the labels reached when a callee transfers control 8435 to a location other than the '``fallthrough label``'. Label constraints 8436 refer to these destinations. 8437#. The optional :ref:`function attributes <fnattrs>` list. 8438#. The optional :ref:`operand bundles <opbundles>` list. 8439 8440Semantics: 8441"""""""""" 8442 8443This instruction is designed to operate as a standard '``call``' 8444instruction in most regards. The primary difference is that it 8445establishes an association with additional labels to define where control 8446flow goes after the call. 8447 8448The output values of a '``callbr``' instruction are available only to 8449the '``fallthrough``' block, not to any '``indirect``' blocks(s). 8450 8451The only use of this today is to implement the "goto" feature of gcc inline 8452assembly where additional labels can be provided as locations for the inline 8453assembly to jump to. 8454 8455Example: 8456"""""""" 8457 8458.. code-block:: llvm 8459 8460 ; "asm goto" without output constraints. 8461 callbr void asm "", "r,!i"(i32 %x) 8462 to label %fallthrough [label %indirect] 8463 8464 ; "asm goto" with output constraints. 8465 <result> = callbr i32 asm "", "=r,r,!i"(i32 %x) 8466 to label %fallthrough [label %indirect] 8467 8468.. _i_resume: 8469 8470'``resume``' Instruction 8471^^^^^^^^^^^^^^^^^^^^^^^^ 8472 8473Syntax: 8474""""""" 8475 8476:: 8477 8478 resume <type> <value> 8479 8480Overview: 8481""""""""" 8482 8483The '``resume``' instruction is a terminator instruction that has no 8484successors. 8485 8486Arguments: 8487"""""""""" 8488 8489The '``resume``' instruction requires one argument, which must have the 8490same type as the result of any '``landingpad``' instruction in the same 8491function. 8492 8493Semantics: 8494"""""""""" 8495 8496The '``resume``' instruction resumes propagation of an existing 8497(in-flight) exception whose unwinding was interrupted with a 8498:ref:`landingpad <i_landingpad>` instruction. 8499 8500Example: 8501"""""""" 8502 8503.. code-block:: llvm 8504 8505 resume { i8*, i32 } %exn 8506 8507.. _i_catchswitch: 8508 8509'``catchswitch``' Instruction 8510^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8511 8512Syntax: 8513""""""" 8514 8515:: 8516 8517 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller 8518 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default> 8519 8520Overview: 8521""""""""" 8522 8523The '``catchswitch``' instruction is used by `LLVM's exception handling system 8524<ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers 8525that may be executed by the :ref:`EH personality routine <personalityfn>`. 8526 8527Arguments: 8528"""""""""" 8529 8530The ``parent`` argument is the token of the funclet that contains the 8531``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet, 8532this operand may be the token ``none``. 8533 8534The ``default`` argument is the label of another basic block beginning with 8535either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination 8536must be a legal target with respect to the ``parent`` links, as described in 8537the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 8538 8539The ``handlers`` are a nonempty list of successor blocks that each begin with a 8540:ref:`catchpad <i_catchpad>` instruction. 8541 8542Semantics: 8543"""""""""" 8544 8545Executing this instruction transfers control to one of the successors in 8546``handlers``, if appropriate, or continues to unwind via the unwind label if 8547present. 8548 8549The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that 8550it must be both the first non-phi instruction and last instruction in the basic 8551block. Therefore, it must be the only non-phi instruction in the block. 8552 8553Example: 8554"""""""" 8555 8556.. code-block:: text 8557 8558 dispatch1: 8559 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller 8560 dispatch2: 8561 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup 8562 8563.. _i_catchret: 8564 8565'``catchret``' Instruction 8566^^^^^^^^^^^^^^^^^^^^^^^^^^ 8567 8568Syntax: 8569""""""" 8570 8571:: 8572 8573 catchret from <token> to label <normal> 8574 8575Overview: 8576""""""""" 8577 8578The '``catchret``' instruction is a terminator instruction that has a 8579single successor. 8580 8581 8582Arguments: 8583"""""""""" 8584 8585The first argument to a '``catchret``' indicates which ``catchpad`` it 8586exits. It must be a :ref:`catchpad <i_catchpad>`. 8587The second argument to a '``catchret``' specifies where control will 8588transfer to next. 8589 8590Semantics: 8591"""""""""" 8592 8593The '``catchret``' instruction ends an existing (in-flight) exception whose 8594unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The 8595:ref:`personality function <personalityfn>` gets a chance to execute arbitrary 8596code to, for example, destroy the active exception. Control then transfers to 8597``normal``. 8598 8599The ``token`` argument must be a token produced by a ``catchpad`` instruction. 8600If the specified ``catchpad`` is not the most-recently-entered not-yet-exited 8601funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 8602the ``catchret``'s behavior is undefined. 8603 8604Example: 8605"""""""" 8606 8607.. code-block:: text 8608 8609 catchret from %catch to label %continue 8610 8611.. _i_cleanupret: 8612 8613'``cleanupret``' Instruction 8614^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8615 8616Syntax: 8617""""""" 8618 8619:: 8620 8621 cleanupret from <value> unwind label <continue> 8622 cleanupret from <value> unwind to caller 8623 8624Overview: 8625""""""""" 8626 8627The '``cleanupret``' instruction is a terminator instruction that has 8628an optional successor. 8629 8630 8631Arguments: 8632"""""""""" 8633 8634The '``cleanupret``' instruction requires one argument, which indicates 8635which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`. 8636If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited 8637funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 8638the ``cleanupret``'s behavior is undefined. 8639 8640The '``cleanupret``' instruction also has an optional successor, ``continue``, 8641which must be the label of another basic block beginning with either a 8642``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must 8643be a legal target with respect to the ``parent`` links, as described in the 8644`exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 8645 8646Semantics: 8647"""""""""" 8648 8649The '``cleanupret``' instruction indicates to the 8650:ref:`personality function <personalityfn>` that one 8651:ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended. 8652It transfers control to ``continue`` or unwinds out of the function. 8653 8654Example: 8655"""""""" 8656 8657.. code-block:: text 8658 8659 cleanupret from %cleanup unwind to caller 8660 cleanupret from %cleanup unwind label %continue 8661 8662.. _i_unreachable: 8663 8664'``unreachable``' Instruction 8665^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8666 8667Syntax: 8668""""""" 8669 8670:: 8671 8672 unreachable 8673 8674Overview: 8675""""""""" 8676 8677The '``unreachable``' instruction has no defined semantics. This 8678instruction is used to inform the optimizer that a particular portion of 8679the code is not reachable. This can be used to indicate that the code 8680after a no-return function cannot be reached, and other facts. 8681 8682Semantics: 8683"""""""""" 8684 8685The '``unreachable``' instruction has no defined semantics. 8686 8687.. _unaryops: 8688 8689Unary Operations 8690----------------- 8691 8692Unary operators require a single operand, execute an operation on 8693it, and produce a single value. The operand might represent multiple 8694data, as is the case with the :ref:`vector <t_vector>` data type. The 8695result value has the same type as its operand. 8696 8697.. _i_fneg: 8698 8699'``fneg``' Instruction 8700^^^^^^^^^^^^^^^^^^^^^^ 8701 8702Syntax: 8703""""""" 8704 8705:: 8706 8707 <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result 8708 8709Overview: 8710""""""""" 8711 8712The '``fneg``' instruction returns the negation of its operand. 8713 8714Arguments: 8715"""""""""" 8716 8717The argument to the '``fneg``' instruction must be a 8718:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8719floating-point values. 8720 8721Semantics: 8722"""""""""" 8723 8724The value produced is a copy of the operand with its sign bit flipped. 8725This instruction can also take any number of :ref:`fast-math 8726flags <fastmath>`, which are optimization hints to enable otherwise 8727unsafe floating-point optimizations: 8728 8729Example: 8730"""""""" 8731 8732.. code-block:: text 8733 8734 <result> = fneg float %val ; yields float:result = -%var 8735 8736.. _binaryops: 8737 8738Binary Operations 8739----------------- 8740 8741Binary operators are used to do most of the computation in a program. 8742They require two operands of the same type, execute an operation on 8743them, and produce a single value. The operands might represent multiple 8744data, as is the case with the :ref:`vector <t_vector>` data type. The 8745result value has the same type as its operands. 8746 8747There are several different binary operators: 8748 8749.. _i_add: 8750 8751'``add``' Instruction 8752^^^^^^^^^^^^^^^^^^^^^ 8753 8754Syntax: 8755""""""" 8756 8757:: 8758 8759 <result> = add <ty> <op1>, <op2> ; yields ty:result 8760 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result 8761 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result 8762 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result 8763 8764Overview: 8765""""""""" 8766 8767The '``add``' instruction returns the sum of its two operands. 8768 8769Arguments: 8770"""""""""" 8771 8772The two arguments to the '``add``' instruction must be 8773:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8774arguments must have identical types. 8775 8776Semantics: 8777"""""""""" 8778 8779The value produced is the integer sum of the two operands. 8780 8781If the sum has unsigned overflow, the result returned is the 8782mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 8783the result. 8784 8785Because LLVM integers use a two's complement representation, this 8786instruction is appropriate for both signed and unsigned integers. 8787 8788``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 8789respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 8790result value of the ``add`` is a :ref:`poison value <poisonvalues>` if 8791unsigned and/or signed overflow, respectively, occurs. 8792 8793Example: 8794"""""""" 8795 8796.. code-block:: text 8797 8798 <result> = add i32 4, %var ; yields i32:result = 4 + %var 8799 8800.. _i_fadd: 8801 8802'``fadd``' Instruction 8803^^^^^^^^^^^^^^^^^^^^^^ 8804 8805Syntax: 8806""""""" 8807 8808:: 8809 8810 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8811 8812Overview: 8813""""""""" 8814 8815The '``fadd``' instruction returns the sum of its two operands. 8816 8817Arguments: 8818"""""""""" 8819 8820The two arguments to the '``fadd``' instruction must be 8821:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8822floating-point values. Both arguments must have identical types. 8823 8824Semantics: 8825"""""""""" 8826 8827The value produced is the floating-point sum of the two operands. 8828This instruction is assumed to execute in the default :ref:`floating-point 8829environment <floatenv>`. 8830This instruction can also take any number of :ref:`fast-math 8831flags <fastmath>`, which are optimization hints to enable otherwise 8832unsafe floating-point optimizations: 8833 8834Example: 8835"""""""" 8836 8837.. code-block:: text 8838 8839 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var 8840 8841.. _i_sub: 8842 8843'``sub``' Instruction 8844^^^^^^^^^^^^^^^^^^^^^ 8845 8846Syntax: 8847""""""" 8848 8849:: 8850 8851 <result> = sub <ty> <op1>, <op2> ; yields ty:result 8852 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result 8853 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result 8854 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result 8855 8856Overview: 8857""""""""" 8858 8859The '``sub``' instruction returns the difference of its two operands. 8860 8861Note that the '``sub``' instruction is used to represent the '``neg``' 8862instruction present in most other intermediate representations. 8863 8864Arguments: 8865"""""""""" 8866 8867The two arguments to the '``sub``' instruction must be 8868:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8869arguments must have identical types. 8870 8871Semantics: 8872"""""""""" 8873 8874The value produced is the integer difference of the two operands. 8875 8876If the difference has unsigned overflow, the result returned is the 8877mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 8878the result. 8879 8880Because LLVM integers use a two's complement representation, this 8881instruction is appropriate for both signed and unsigned integers. 8882 8883``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 8884respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 8885result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if 8886unsigned and/or signed overflow, respectively, occurs. 8887 8888Example: 8889"""""""" 8890 8891.. code-block:: text 8892 8893 <result> = sub i32 4, %var ; yields i32:result = 4 - %var 8894 <result> = sub i32 0, %val ; yields i32:result = -%var 8895 8896.. _i_fsub: 8897 8898'``fsub``' Instruction 8899^^^^^^^^^^^^^^^^^^^^^^ 8900 8901Syntax: 8902""""""" 8903 8904:: 8905 8906 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8907 8908Overview: 8909""""""""" 8910 8911The '``fsub``' instruction returns the difference of its two operands. 8912 8913Arguments: 8914"""""""""" 8915 8916The two arguments to the '``fsub``' instruction must be 8917:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8918floating-point values. Both arguments must have identical types. 8919 8920Semantics: 8921"""""""""" 8922 8923The value produced is the floating-point difference of the two operands. 8924This instruction is assumed to execute in the default :ref:`floating-point 8925environment <floatenv>`. 8926This instruction can also take any number of :ref:`fast-math 8927flags <fastmath>`, which are optimization hints to enable otherwise 8928unsafe floating-point optimizations: 8929 8930Example: 8931"""""""" 8932 8933.. code-block:: text 8934 8935 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var 8936 <result> = fsub float -0.0, %val ; yields float:result = -%var 8937 8938.. _i_mul: 8939 8940'``mul``' Instruction 8941^^^^^^^^^^^^^^^^^^^^^ 8942 8943Syntax: 8944""""""" 8945 8946:: 8947 8948 <result> = mul <ty> <op1>, <op2> ; yields ty:result 8949 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result 8950 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result 8951 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result 8952 8953Overview: 8954""""""""" 8955 8956The '``mul``' instruction returns the product of its two operands. 8957 8958Arguments: 8959"""""""""" 8960 8961The two arguments to the '``mul``' instruction must be 8962:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8963arguments must have identical types. 8964 8965Semantics: 8966"""""""""" 8967 8968The value produced is the integer product of the two operands. 8969 8970If the result of the multiplication has unsigned overflow, the result 8971returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the 8972bit width of the result. 8973 8974Because LLVM integers use a two's complement representation, and the 8975result is the same width as the operands, this instruction returns the 8976correct result for both signed and unsigned integers. If a full product 8977(e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be 8978sign-extended or zero-extended as appropriate to the width of the full 8979product. 8980 8981``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 8982respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 8983result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if 8984unsigned and/or signed overflow, respectively, occurs. 8985 8986Example: 8987"""""""" 8988 8989.. code-block:: text 8990 8991 <result> = mul i32 4, %var ; yields i32:result = 4 * %var 8992 8993.. _i_fmul: 8994 8995'``fmul``' Instruction 8996^^^^^^^^^^^^^^^^^^^^^^ 8997 8998Syntax: 8999""""""" 9000 9001:: 9002 9003 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 9004 9005Overview: 9006""""""""" 9007 9008The '``fmul``' instruction returns the product of its two operands. 9009 9010Arguments: 9011"""""""""" 9012 9013The two arguments to the '``fmul``' instruction must be 9014:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 9015floating-point values. Both arguments must have identical types. 9016 9017Semantics: 9018"""""""""" 9019 9020The value produced is the floating-point product of the two operands. 9021This instruction is assumed to execute in the default :ref:`floating-point 9022environment <floatenv>`. 9023This instruction can also take any number of :ref:`fast-math 9024flags <fastmath>`, which are optimization hints to enable otherwise 9025unsafe floating-point optimizations: 9026 9027Example: 9028"""""""" 9029 9030.. code-block:: text 9031 9032 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var 9033 9034.. _i_udiv: 9035 9036'``udiv``' Instruction 9037^^^^^^^^^^^^^^^^^^^^^^ 9038 9039Syntax: 9040""""""" 9041 9042:: 9043 9044 <result> = udiv <ty> <op1>, <op2> ; yields ty:result 9045 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result 9046 9047Overview: 9048""""""""" 9049 9050The '``udiv``' instruction returns the quotient of its two operands. 9051 9052Arguments: 9053"""""""""" 9054 9055The two arguments to the '``udiv``' instruction must be 9056:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9057arguments must have identical types. 9058 9059Semantics: 9060"""""""""" 9061 9062The value produced is the unsigned integer quotient of the two operands. 9063 9064Note that unsigned integer division and signed integer division are 9065distinct operations; for signed integer division, use '``sdiv``'. 9066 9067Division by zero is undefined behavior. For vectors, if any element 9068of the divisor is zero, the operation has undefined behavior. 9069 9070 9071If the ``exact`` keyword is present, the result value of the ``udiv`` is 9072a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as 9073such, "((a udiv exact b) mul b) == a"). 9074 9075Example: 9076"""""""" 9077 9078.. code-block:: text 9079 9080 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var 9081 9082.. _i_sdiv: 9083 9084'``sdiv``' Instruction 9085^^^^^^^^^^^^^^^^^^^^^^ 9086 9087Syntax: 9088""""""" 9089 9090:: 9091 9092 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result 9093 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result 9094 9095Overview: 9096""""""""" 9097 9098The '``sdiv``' instruction returns the quotient of its two operands. 9099 9100Arguments: 9101"""""""""" 9102 9103The two arguments to the '``sdiv``' instruction must be 9104:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9105arguments must have identical types. 9106 9107Semantics: 9108"""""""""" 9109 9110The value produced is the signed integer quotient of the two operands 9111rounded towards zero. 9112 9113Note that signed integer division and unsigned integer division are 9114distinct operations; for unsigned integer division, use '``udiv``'. 9115 9116Division by zero is undefined behavior. For vectors, if any element 9117of the divisor is zero, the operation has undefined behavior. 9118Overflow also leads to undefined behavior; this is a rare case, but can 9119occur, for example, by doing a 32-bit division of -2147483648 by -1. 9120 9121If the ``exact`` keyword is present, the result value of the ``sdiv`` is 9122a :ref:`poison value <poisonvalues>` if the result would be rounded. 9123 9124Example: 9125"""""""" 9126 9127.. code-block:: text 9128 9129 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var 9130 9131.. _i_fdiv: 9132 9133'``fdiv``' Instruction 9134^^^^^^^^^^^^^^^^^^^^^^ 9135 9136Syntax: 9137""""""" 9138 9139:: 9140 9141 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 9142 9143Overview: 9144""""""""" 9145 9146The '``fdiv``' instruction returns the quotient of its two operands. 9147 9148Arguments: 9149"""""""""" 9150 9151The two arguments to the '``fdiv``' instruction must be 9152:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 9153floating-point values. Both arguments must have identical types. 9154 9155Semantics: 9156"""""""""" 9157 9158The value produced is the floating-point quotient of the two operands. 9159This instruction is assumed to execute in the default :ref:`floating-point 9160environment <floatenv>`. 9161This instruction can also take any number of :ref:`fast-math 9162flags <fastmath>`, which are optimization hints to enable otherwise 9163unsafe floating-point optimizations: 9164 9165Example: 9166"""""""" 9167 9168.. code-block:: text 9169 9170 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var 9171 9172.. _i_urem: 9173 9174'``urem``' Instruction 9175^^^^^^^^^^^^^^^^^^^^^^ 9176 9177Syntax: 9178""""""" 9179 9180:: 9181 9182 <result> = urem <ty> <op1>, <op2> ; yields ty:result 9183 9184Overview: 9185""""""""" 9186 9187The '``urem``' instruction returns the remainder from the unsigned 9188division of its two arguments. 9189 9190Arguments: 9191"""""""""" 9192 9193The two arguments to the '``urem``' instruction must be 9194:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9195arguments must have identical types. 9196 9197Semantics: 9198"""""""""" 9199 9200This instruction returns the unsigned integer *remainder* of a division. 9201This instruction always performs an unsigned division to get the 9202remainder. 9203 9204Note that unsigned integer remainder and signed integer remainder are 9205distinct operations; for signed integer remainder, use '``srem``'. 9206 9207Taking the remainder of a division by zero is undefined behavior. 9208For vectors, if any element of the divisor is zero, the operation has 9209undefined behavior. 9210 9211Example: 9212"""""""" 9213 9214.. code-block:: text 9215 9216 <result> = urem i32 4, %var ; yields i32:result = 4 % %var 9217 9218.. _i_srem: 9219 9220'``srem``' Instruction 9221^^^^^^^^^^^^^^^^^^^^^^ 9222 9223Syntax: 9224""""""" 9225 9226:: 9227 9228 <result> = srem <ty> <op1>, <op2> ; yields ty:result 9229 9230Overview: 9231""""""""" 9232 9233The '``srem``' instruction returns the remainder from the signed 9234division of its two operands. This instruction can also take 9235:ref:`vector <t_vector>` versions of the values in which case the elements 9236must be integers. 9237 9238Arguments: 9239"""""""""" 9240 9241The two arguments to the '``srem``' instruction must be 9242:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9243arguments must have identical types. 9244 9245Semantics: 9246"""""""""" 9247 9248This instruction returns the *remainder* of a division (where the result 9249is either zero or has the same sign as the dividend, ``op1``), not the 9250*modulo* operator (where the result is either zero or has the same sign 9251as the divisor, ``op2``) of a value. For more information about the 9252difference, see `The Math 9253Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a 9254table of how this is implemented in various languages, please see 9255`Wikipedia: modulo 9256operation <http://en.wikipedia.org/wiki/Modulo_operation>`_. 9257 9258Note that signed integer remainder and unsigned integer remainder are 9259distinct operations; for unsigned integer remainder, use '``urem``'. 9260 9261Taking the remainder of a division by zero is undefined behavior. 9262For vectors, if any element of the divisor is zero, the operation has 9263undefined behavior. 9264Overflow also leads to undefined behavior; this is a rare case, but can 9265occur, for example, by taking the remainder of a 32-bit division of 9266-2147483648 by -1. (The remainder doesn't actually overflow, but this 9267rule lets srem be implemented using instructions that return both the 9268result of the division and the remainder.) 9269 9270Example: 9271"""""""" 9272 9273.. code-block:: text 9274 9275 <result> = srem i32 4, %var ; yields i32:result = 4 % %var 9276 9277.. _i_frem: 9278 9279'``frem``' Instruction 9280^^^^^^^^^^^^^^^^^^^^^^ 9281 9282Syntax: 9283""""""" 9284 9285:: 9286 9287 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 9288 9289Overview: 9290""""""""" 9291 9292The '``frem``' instruction returns the remainder from the division of 9293its two operands. 9294 9295Arguments: 9296"""""""""" 9297 9298The two arguments to the '``frem``' instruction must be 9299:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 9300floating-point values. Both arguments must have identical types. 9301 9302Semantics: 9303"""""""""" 9304 9305The value produced is the floating-point remainder of the two operands. 9306This is the same output as a libm '``fmod``' function, but without any 9307possibility of setting ``errno``. The remainder has the same sign as the 9308dividend. 9309This instruction is assumed to execute in the default :ref:`floating-point 9310environment <floatenv>`. 9311This instruction can also take any number of :ref:`fast-math 9312flags <fastmath>`, which are optimization hints to enable otherwise 9313unsafe floating-point optimizations: 9314 9315Example: 9316"""""""" 9317 9318.. code-block:: text 9319 9320 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var 9321 9322.. _bitwiseops: 9323 9324Bitwise Binary Operations 9325------------------------- 9326 9327Bitwise binary operators are used to do various forms of bit-twiddling 9328in a program. They are generally very efficient instructions and can 9329commonly be strength reduced from other instructions. They require two 9330operands of the same type, execute an operation on them, and produce a 9331single value. The resulting value is the same type as its operands. 9332 9333.. _i_shl: 9334 9335'``shl``' Instruction 9336^^^^^^^^^^^^^^^^^^^^^ 9337 9338Syntax: 9339""""""" 9340 9341:: 9342 9343 <result> = shl <ty> <op1>, <op2> ; yields ty:result 9344 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result 9345 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result 9346 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result 9347 9348Overview: 9349""""""""" 9350 9351The '``shl``' instruction returns the first operand shifted to the left 9352a specified number of bits. 9353 9354Arguments: 9355"""""""""" 9356 9357Both arguments to the '``shl``' instruction must be the same 9358:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9359'``op2``' is treated as an unsigned value. 9360 9361Semantics: 9362"""""""""" 9363 9364The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`, 9365where ``n`` is the width of the result. If ``op2`` is (statically or 9366dynamically) equal to or larger than the number of bits in 9367``op1``, this instruction returns a :ref:`poison value <poisonvalues>`. 9368If the arguments are vectors, each vector element of ``op1`` is shifted 9369by the corresponding shift amount in ``op2``. 9370 9371If the ``nuw`` keyword is present, then the shift produces a poison 9372value if it shifts out any non-zero bits. 9373If the ``nsw`` keyword is present, then the shift produces a poison 9374value if it shifts out any bits that disagree with the resultant sign bit. 9375 9376Example: 9377"""""""" 9378 9379.. code-block:: text 9380 9381 <result> = shl i32 4, %var ; yields i32: 4 << %var 9382 <result> = shl i32 4, 2 ; yields i32: 16 9383 <result> = shl i32 1, 10 ; yields i32: 1024 9384 <result> = shl i32 1, 32 ; undefined 9385 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4> 9386 9387.. _i_lshr: 9388 9389 9390'``lshr``' Instruction 9391^^^^^^^^^^^^^^^^^^^^^^ 9392 9393Syntax: 9394""""""" 9395 9396:: 9397 9398 <result> = lshr <ty> <op1>, <op2> ; yields ty:result 9399 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result 9400 9401Overview: 9402""""""""" 9403 9404The '``lshr``' instruction (logical shift right) returns the first 9405operand shifted to the right a specified number of bits with zero fill. 9406 9407Arguments: 9408"""""""""" 9409 9410Both arguments to the '``lshr``' instruction must be the same 9411:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9412'``op2``' is treated as an unsigned value. 9413 9414Semantics: 9415"""""""""" 9416 9417This instruction always performs a logical shift right operation. The 9418most significant bits of the result will be filled with zero bits after 9419the shift. If ``op2`` is (statically or dynamically) equal to or larger 9420than the number of bits in ``op1``, this instruction returns a :ref:`poison 9421value <poisonvalues>`. If the arguments are vectors, each vector element 9422of ``op1`` is shifted by the corresponding shift amount in ``op2``. 9423 9424If the ``exact`` keyword is present, the result value of the ``lshr`` is 9425a poison value if any of the bits shifted out are non-zero. 9426 9427Example: 9428"""""""" 9429 9430.. code-block:: text 9431 9432 <result> = lshr i32 4, 1 ; yields i32:result = 2 9433 <result> = lshr i32 4, 2 ; yields i32:result = 1 9434 <result> = lshr i8 4, 3 ; yields i8:result = 0 9435 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F 9436 <result> = lshr i32 1, 32 ; undefined 9437 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1> 9438 9439.. _i_ashr: 9440 9441'``ashr``' Instruction 9442^^^^^^^^^^^^^^^^^^^^^^ 9443 9444Syntax: 9445""""""" 9446 9447:: 9448 9449 <result> = ashr <ty> <op1>, <op2> ; yields ty:result 9450 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result 9451 9452Overview: 9453""""""""" 9454 9455The '``ashr``' instruction (arithmetic shift right) returns the first 9456operand shifted to the right a specified number of bits with sign 9457extension. 9458 9459Arguments: 9460"""""""""" 9461 9462Both arguments to the '``ashr``' instruction must be the same 9463:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9464'``op2``' is treated as an unsigned value. 9465 9466Semantics: 9467"""""""""" 9468 9469This instruction always performs an arithmetic shift right operation, 9470The most significant bits of the result will be filled with the sign bit 9471of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger 9472than the number of bits in ``op1``, this instruction returns a :ref:`poison 9473value <poisonvalues>`. If the arguments are vectors, each vector element 9474of ``op1`` is shifted by the corresponding shift amount in ``op2``. 9475 9476If the ``exact`` keyword is present, the result value of the ``ashr`` is 9477a poison value if any of the bits shifted out are non-zero. 9478 9479Example: 9480"""""""" 9481 9482.. code-block:: text 9483 9484 <result> = ashr i32 4, 1 ; yields i32:result = 2 9485 <result> = ashr i32 4, 2 ; yields i32:result = 1 9486 <result> = ashr i8 4, 3 ; yields i8:result = 0 9487 <result> = ashr i8 -2, 1 ; yields i8:result = -1 9488 <result> = ashr i32 1, 32 ; undefined 9489 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0> 9490 9491.. _i_and: 9492 9493'``and``' Instruction 9494^^^^^^^^^^^^^^^^^^^^^ 9495 9496Syntax: 9497""""""" 9498 9499:: 9500 9501 <result> = and <ty> <op1>, <op2> ; yields ty:result 9502 9503Overview: 9504""""""""" 9505 9506The '``and``' instruction returns the bitwise logical and of its two 9507operands. 9508 9509Arguments: 9510"""""""""" 9511 9512The two arguments to the '``and``' instruction must be 9513:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9514arguments must have identical types. 9515 9516Semantics: 9517"""""""""" 9518 9519The truth table used for the '``and``' instruction is: 9520 9521+-----+-----+-----+ 9522| In0 | In1 | Out | 9523+-----+-----+-----+ 9524| 0 | 0 | 0 | 9525+-----+-----+-----+ 9526| 0 | 1 | 0 | 9527+-----+-----+-----+ 9528| 1 | 0 | 0 | 9529+-----+-----+-----+ 9530| 1 | 1 | 1 | 9531+-----+-----+-----+ 9532 9533Example: 9534"""""""" 9535 9536.. code-block:: text 9537 9538 <result> = and i32 4, %var ; yields i32:result = 4 & %var 9539 <result> = and i32 15, 40 ; yields i32:result = 8 9540 <result> = and i32 4, 8 ; yields i32:result = 0 9541 9542.. _i_or: 9543 9544'``or``' Instruction 9545^^^^^^^^^^^^^^^^^^^^ 9546 9547Syntax: 9548""""""" 9549 9550:: 9551 9552 <result> = or <ty> <op1>, <op2> ; yields ty:result 9553 9554Overview: 9555""""""""" 9556 9557The '``or``' instruction returns the bitwise logical inclusive or of its 9558two operands. 9559 9560Arguments: 9561"""""""""" 9562 9563The two arguments to the '``or``' instruction must be 9564:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9565arguments must have identical types. 9566 9567Semantics: 9568"""""""""" 9569 9570The truth table used for the '``or``' instruction is: 9571 9572+-----+-----+-----+ 9573| In0 | In1 | Out | 9574+-----+-----+-----+ 9575| 0 | 0 | 0 | 9576+-----+-----+-----+ 9577| 0 | 1 | 1 | 9578+-----+-----+-----+ 9579| 1 | 0 | 1 | 9580+-----+-----+-----+ 9581| 1 | 1 | 1 | 9582+-----+-----+-----+ 9583 9584Example: 9585"""""""" 9586 9587:: 9588 9589 <result> = or i32 4, %var ; yields i32:result = 4 | %var 9590 <result> = or i32 15, 40 ; yields i32:result = 47 9591 <result> = or i32 4, 8 ; yields i32:result = 12 9592 9593.. _i_xor: 9594 9595'``xor``' Instruction 9596^^^^^^^^^^^^^^^^^^^^^ 9597 9598Syntax: 9599""""""" 9600 9601:: 9602 9603 <result> = xor <ty> <op1>, <op2> ; yields ty:result 9604 9605Overview: 9606""""""""" 9607 9608The '``xor``' instruction returns the bitwise logical exclusive or of 9609its two operands. The ``xor`` is used to implement the "one's 9610complement" operation, which is the "~" operator in C. 9611 9612Arguments: 9613"""""""""" 9614 9615The two arguments to the '``xor``' instruction must be 9616:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9617arguments must have identical types. 9618 9619Semantics: 9620"""""""""" 9621 9622The truth table used for the '``xor``' instruction is: 9623 9624+-----+-----+-----+ 9625| In0 | In1 | Out | 9626+-----+-----+-----+ 9627| 0 | 0 | 0 | 9628+-----+-----+-----+ 9629| 0 | 1 | 1 | 9630+-----+-----+-----+ 9631| 1 | 0 | 1 | 9632+-----+-----+-----+ 9633| 1 | 1 | 0 | 9634+-----+-----+-----+ 9635 9636Example: 9637"""""""" 9638 9639.. code-block:: text 9640 9641 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var 9642 <result> = xor i32 15, 40 ; yields i32:result = 39 9643 <result> = xor i32 4, 8 ; yields i32:result = 12 9644 <result> = xor i32 %V, -1 ; yields i32:result = ~%V 9645 9646Vector Operations 9647----------------- 9648 9649LLVM supports several instructions to represent vector operations in a 9650target-independent manner. These instructions cover the element-access 9651and vector-specific operations needed to process vectors effectively. 9652While LLVM does directly support these vector operations, many 9653sophisticated algorithms will want to use target-specific intrinsics to 9654take full advantage of a specific target. 9655 9656.. _i_extractelement: 9657 9658'``extractelement``' Instruction 9659^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9660 9661Syntax: 9662""""""" 9663 9664:: 9665 9666 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty> 9667 <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty> 9668 9669Overview: 9670""""""""" 9671 9672The '``extractelement``' instruction extracts a single scalar element 9673from a vector at a specified index. 9674 9675Arguments: 9676"""""""""" 9677 9678The first operand of an '``extractelement``' instruction is a value of 9679:ref:`vector <t_vector>` type. The second operand is an index indicating 9680the position from which to extract the element. The index may be a 9681variable of any integer type. 9682 9683Semantics: 9684"""""""""" 9685 9686The result is a scalar of the same type as the element type of ``val``. 9687Its value is the value at position ``idx`` of ``val``. If ``idx`` 9688exceeds the length of ``val`` for a fixed-length vector, the result is a 9689:ref:`poison value <poisonvalues>`. For a scalable vector, if the value 9690of ``idx`` exceeds the runtime length of the vector, the result is a 9691:ref:`poison value <poisonvalues>`. 9692 9693Example: 9694"""""""" 9695 9696.. code-block:: text 9697 9698 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32 9699 9700.. _i_insertelement: 9701 9702'``insertelement``' Instruction 9703^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9704 9705Syntax: 9706""""""" 9707 9708:: 9709 9710 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>> 9711 <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>> 9712 9713Overview: 9714""""""""" 9715 9716The '``insertelement``' instruction inserts a scalar element into a 9717vector at a specified index. 9718 9719Arguments: 9720"""""""""" 9721 9722The first operand of an '``insertelement``' instruction is a value of 9723:ref:`vector <t_vector>` type. The second operand is a scalar value whose 9724type must equal the element type of the first operand. The third operand 9725is an index indicating the position at which to insert the value. The 9726index may be a variable of any integer type. 9727 9728Semantics: 9729"""""""""" 9730 9731The result is a vector of the same type as ``val``. Its element values 9732are those of ``val`` except at position ``idx``, where it gets the value 9733``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector, 9734the result is a :ref:`poison value <poisonvalues>`. For a scalable vector, 9735if the value of ``idx`` exceeds the runtime length of the vector, the result 9736is a :ref:`poison value <poisonvalues>`. 9737 9738Example: 9739"""""""" 9740 9741.. code-block:: text 9742 9743 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32> 9744 9745.. _i_shufflevector: 9746 9747'``shufflevector``' Instruction 9748^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9749 9750Syntax: 9751""""""" 9752 9753:: 9754 9755 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>> 9756 <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>> 9757 9758Overview: 9759""""""""" 9760 9761The '``shufflevector``' instruction constructs a permutation of elements 9762from two input vectors, returning a vector with the same element type as 9763the input and length that is the same as the shuffle mask. 9764 9765Arguments: 9766"""""""""" 9767 9768The first two operands of a '``shufflevector``' instruction are vectors 9769with the same type. The third argument is a shuffle mask vector constant 9770whose element type is ``i32``. The mask vector elements must be constant 9771integers or ``undef`` values. The result of the instruction is a vector 9772whose length is the same as the shuffle mask and whose element type is the 9773same as the element type of the first two operands. 9774 9775Semantics: 9776"""""""""" 9777 9778The elements of the two input vectors are numbered from left to right 9779across both of the vectors. For each element of the result vector, the 9780shuffle mask selects an element from one of the input vectors to copy 9781to the result. Non-negative elements in the mask represent an index 9782into the concatenated pair of input vectors. 9783 9784If the shuffle mask is undefined, the result vector is undefined. If 9785the shuffle mask selects an undefined element from one of the input 9786vectors, the resulting element is undefined. An undefined element 9787in the mask vector specifies that the resulting element is undefined. 9788An undefined element in the mask vector prevents a poisoned vector 9789element from propagating. 9790 9791For scalable vectors, the only valid mask values at present are 9792``zeroinitializer`` and ``undef``, since we cannot write all indices as 9793literals for a vector with a length unknown at compile time. 9794 9795Example: 9796"""""""" 9797 9798.. code-block:: text 9799 9800 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 9801 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32> 9802 <result> = shufflevector <4 x i32> %v1, <4 x i32> undef, 9803 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle. 9804 <result> = shufflevector <8 x i32> %v1, <8 x i32> undef, 9805 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> 9806 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 9807 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32> 9808 9809Aggregate Operations 9810-------------------- 9811 9812LLVM supports several instructions for working with 9813:ref:`aggregate <t_aggregate>` values. 9814 9815.. _i_extractvalue: 9816 9817'``extractvalue``' Instruction 9818^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9819 9820Syntax: 9821""""""" 9822 9823:: 9824 9825 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}* 9826 9827Overview: 9828""""""""" 9829 9830The '``extractvalue``' instruction extracts the value of a member field 9831from an :ref:`aggregate <t_aggregate>` value. 9832 9833Arguments: 9834"""""""""" 9835 9836The first operand of an '``extractvalue``' instruction is a value of 9837:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are 9838constant indices to specify which value to extract in a similar manner 9839as indices in a '``getelementptr``' instruction. 9840 9841The major differences to ``getelementptr`` indexing are: 9842 9843- Since the value being indexed is not a pointer, the first index is 9844 omitted and assumed to be zero. 9845- At least one index must be specified. 9846- Not only struct indices but also array indices must be in bounds. 9847 9848Semantics: 9849"""""""""" 9850 9851The result is the value at the position in the aggregate specified by 9852the index operands. 9853 9854Example: 9855"""""""" 9856 9857.. code-block:: text 9858 9859 <result> = extractvalue {i32, float} %agg, 0 ; yields i32 9860 9861.. _i_insertvalue: 9862 9863'``insertvalue``' Instruction 9864^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9865 9866Syntax: 9867""""""" 9868 9869:: 9870 9871 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type> 9872 9873Overview: 9874""""""""" 9875 9876The '``insertvalue``' instruction inserts a value into a member field in 9877an :ref:`aggregate <t_aggregate>` value. 9878 9879Arguments: 9880"""""""""" 9881 9882The first operand of an '``insertvalue``' instruction is a value of 9883:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is 9884a first-class value to insert. The following operands are constant 9885indices indicating the position at which to insert the value in a 9886similar manner as indices in a '``extractvalue``' instruction. The value 9887to insert must have the same type as the value identified by the 9888indices. 9889 9890Semantics: 9891"""""""""" 9892 9893The result is an aggregate of the same type as ``val``. Its value is 9894that of ``val`` except that the value at the position specified by the 9895indices is that of ``elt``. 9896 9897Example: 9898"""""""" 9899 9900.. code-block:: llvm 9901 9902 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef} 9903 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val} 9904 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}} 9905 9906.. _memoryops: 9907 9908Memory Access and Addressing Operations 9909--------------------------------------- 9910 9911A key design point of an SSA-based representation is how it represents 9912memory. In LLVM, no memory locations are in SSA form, which makes things 9913very simple. This section describes how to read, write, and allocate 9914memory in LLVM. 9915 9916.. _i_alloca: 9917 9918'``alloca``' Instruction 9919^^^^^^^^^^^^^^^^^^^^^^^^ 9920 9921Syntax: 9922""""""" 9923 9924:: 9925 9926 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result 9927 9928Overview: 9929""""""""" 9930 9931The '``alloca``' instruction allocates memory on the stack frame of the 9932currently executing function, to be automatically released when this 9933function returns to its caller. If the address space is not explicitly 9934specified, the object is allocated in the alloca address space from the 9935:ref:`datalayout string<langref_datalayout>`. 9936 9937Arguments: 9938"""""""""" 9939 9940The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements`` 9941bytes of memory on the runtime stack, returning a pointer of the 9942appropriate type to the program. If "NumElements" is specified, it is 9943the number of elements allocated, otherwise "NumElements" is defaulted 9944to be one. If a constant alignment is specified, the value result of the 9945allocation is guaranteed to be aligned to at least that boundary. The 9946alignment may not be greater than ``1 << 32``. If not specified, or if 9947zero, the target can choose to align the allocation on any convenient 9948boundary compatible with the type. 9949 9950'``type``' may be any sized type. 9951 9952Semantics: 9953"""""""""" 9954 9955Memory is allocated; a pointer is returned. The allocated memory is 9956uninitialized, and loading from uninitialized memory produces an undefined 9957value. The operation itself is undefined if there is insufficient stack 9958space for the allocation.'``alloca``'d memory is automatically released 9959when the function returns. The '``alloca``' instruction is commonly used 9960to represent automatic variables that must have an address available. When 9961the function returns (either with the ``ret`` or ``resume`` instructions), 9962the memory is reclaimed. Allocating zero bytes is legal, but the returned 9963pointer may not be unique. The order in which memory is allocated (ie., 9964which way the stack grows) is not specified. 9965 9966Note that '``alloca``' outside of the alloca address space from the 9967:ref:`datalayout string<langref_datalayout>` is meaningful only if the 9968target has assigned it a semantics. 9969 9970If the returned pointer is used by :ref:`llvm.lifetime.start <int_lifestart>`, 9971the returned object is initially dead. 9972See :ref:`llvm.lifetime.start <int_lifestart>` and 9973:ref:`llvm.lifetime.end <int_lifeend>` for the precise semantics of 9974lifetime-manipulating intrinsics. 9975 9976Example: 9977"""""""" 9978 9979.. code-block:: llvm 9980 9981 %ptr = alloca i32 ; yields i32*:ptr 9982 %ptr = alloca i32, i32 4 ; yields i32*:ptr 9983 %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr 9984 %ptr = alloca i32, align 1024 ; yields i32*:ptr 9985 9986.. _i_load: 9987 9988'``load``' Instruction 9989^^^^^^^^^^^^^^^^^^^^^^ 9990 9991Syntax: 9992""""""" 9993 9994:: 9995 9996 <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>] 9997 <result> = load atomic [volatile] <ty>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] 9998 !<nontemp_node> = !{ i32 1 } 9999 !<empty_node> = !{} 10000 !<deref_bytes_node> = !{ i64 <dereferenceable_bytes> } 10001 !<align_node> = !{ i64 <value_alignment> } 10002 10003Overview: 10004""""""""" 10005 10006The '``load``' instruction is used to read from memory. 10007 10008Arguments: 10009"""""""""" 10010 10011The argument to the ``load`` instruction specifies the memory address from which 10012to load. The type specified must be a :ref:`first class <t_firstclass>` type of 10013known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If 10014the ``load`` is marked as ``volatile``, then the optimizer is not allowed to 10015modify the number or order of execution of this ``load`` with other 10016:ref:`volatile operations <volatile>`. 10017 10018If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering 10019<ordering>` and optional ``syncscope("<target-scope>")`` argument. The 10020``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions. 10021Atomic loads produce :ref:`defined <memmodel>` results when they may see 10022multiple atomic stores. The type of the pointee must be an integer, pointer, or 10023floating-point type whose bit width is a power of two greater than or equal to 10024eight and less than or equal to a target-specific size limit. ``align`` must be 10025explicitly specified on atomic loads, and the load has undefined behavior if the 10026alignment is not set to a value which is at least the size in bytes of the 10027pointee. ``!nontemporal`` does not have any defined semantics for atomic loads. 10028 10029The optional constant ``align`` argument specifies the alignment of the 10030operation (that is, the alignment of the memory address). A value of 0 10031or an omitted ``align`` argument means that the operation has the ABI 10032alignment for the target. It is the responsibility of the code emitter 10033to ensure that the alignment information is correct. Overestimating the 10034alignment results in undefined behavior. Underestimating the alignment 10035may produce less efficient code. An alignment of 1 is always safe. The 10036maximum possible alignment is ``1 << 32``. An alignment value higher 10037than the size of the loaded type implies memory up to the alignment 10038value bytes can be safely loaded without trapping in the default 10039address space. Access of the high bytes can interfere with debugging 10040tools, so should not be accessed if the function has the 10041``sanitize_thread`` or ``sanitize_address`` attributes. 10042 10043The optional ``!nontemporal`` metadata must reference a single 10044metadata name ``<nontemp_node>`` corresponding to a metadata node with one 10045``i32`` entry of value 1. The existence of the ``!nontemporal`` 10046metadata on the instruction tells the optimizer and code generator 10047that this load is not expected to be reused in the cache. The code 10048generator may select special instructions to save cache bandwidth, such 10049as the ``MOVNT`` instruction on x86. 10050 10051The optional ``!invariant.load`` metadata must reference a single 10052metadata name ``<empty_node>`` corresponding to a metadata node with no 10053entries. If a load instruction tagged with the ``!invariant.load`` 10054metadata is executed, the memory location referenced by the load has 10055to contain the same value at all points in the program where the 10056memory location is dereferenceable; otherwise, the behavior is 10057undefined. 10058 10059The optional ``!invariant.group`` metadata must reference a single metadata name 10060 ``<empty_node>`` corresponding to a metadata node with no entries. 10061 See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>`. 10062 10063The optional ``!nonnull`` metadata must reference a single 10064metadata name ``<empty_node>`` corresponding to a metadata node with no 10065entries. The existence of the ``!nonnull`` metadata on the 10066instruction tells the optimizer that the value loaded is known to 10067never be null. If the value is null at runtime, the behavior is undefined. 10068This is analogous to the ``nonnull`` attribute on parameters and return 10069values. This metadata can only be applied to loads of a pointer type. 10070 10071The optional ``!dereferenceable`` metadata must reference a single metadata 10072name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 10073entry. 10074See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>`. 10075 10076The optional ``!dereferenceable_or_null`` metadata must reference a single 10077metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 10078``i64`` entry. 10079See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null 10080<md_dereferenceable_or_null>`. 10081 10082The optional ``!align`` metadata must reference a single metadata name 10083``<align_node>`` corresponding to a metadata node with one ``i64`` entry. 10084The existence of the ``!align`` metadata on the instruction tells the 10085optimizer that the value loaded is known to be aligned to a boundary specified 10086by the integer value in the metadata node. The alignment must be a power of 2. 10087This is analogous to the ''align'' attribute on parameters and return values. 10088This metadata can only be applied to loads of a pointer type. If the returned 10089value is not appropriately aligned at runtime, the behavior is undefined. 10090 10091The optional ``!noundef`` metadata must reference a single metadata name 10092``<empty_node>`` corresponding to a node with no entries. The existence of 10093``!noundef`` metadata on the instruction tells the optimizer that the value 10094loaded is known to be :ref:`well defined <welldefinedvalues>`. 10095If the value isn't well defined, the behavior is undefined. 10096 10097Semantics: 10098"""""""""" 10099 10100The location of memory pointed to is loaded. If the value being loaded 10101is of scalar type then the number of bytes read does not exceed the 10102minimum number of bytes needed to hold all bits of the type. For 10103example, loading an ``i24`` reads at most three bytes. When loading a 10104value of a type like ``i20`` with a size that is not an integral number 10105of bytes, the result is undefined if the value was not originally 10106written using a store of the same type. 10107If the value being loaded is of aggregate type, the bytes that correspond to 10108padding may be accessed but are ignored, because it is impossible to observe 10109padding from the loaded aggregate value. 10110If ``<pointer>`` is not a well-defined value, the behavior is undefined. 10111 10112Examples: 10113""""""""" 10114 10115.. code-block:: llvm 10116 10117 %ptr = alloca i32 ; yields i32*:ptr 10118 store i32 3, i32* %ptr ; yields void 10119 %val = load i32, i32* %ptr ; yields i32:val = i32 3 10120 10121.. _i_store: 10122 10123'``store``' Instruction 10124^^^^^^^^^^^^^^^^^^^^^^^ 10125 10126Syntax: 10127""""""" 10128 10129:: 10130 10131 store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.group !<empty_node>] ; yields void 10132 store atomic [volatile] <ty> <value>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] ; yields void 10133 !<nontemp_node> = !{ i32 1 } 10134 !<empty_node> = !{} 10135 10136Overview: 10137""""""""" 10138 10139The '``store``' instruction is used to write to memory. 10140 10141Arguments: 10142"""""""""" 10143 10144There are two arguments to the ``store`` instruction: a value to store and an 10145address at which to store it. The type of the ``<pointer>`` operand must be a 10146pointer to the :ref:`first class <t_firstclass>` type of the ``<value>`` 10147operand. If the ``store`` is marked as ``volatile``, then the optimizer is not 10148allowed to modify the number or order of execution of this ``store`` with other 10149:ref:`volatile operations <volatile>`. Only values of :ref:`first class 10150<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque 10151structural type <t_opaque>`) can be stored. 10152 10153If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering 10154<ordering>` and optional ``syncscope("<target-scope>")`` argument. The 10155``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions. 10156Atomic loads produce :ref:`defined <memmodel>` results when they may see 10157multiple atomic stores. The type of the pointee must be an integer, pointer, or 10158floating-point type whose bit width is a power of two greater than or equal to 10159eight and less than or equal to a target-specific size limit. ``align`` must be 10160explicitly specified on atomic stores, and the store has undefined behavior if 10161the alignment is not set to a value which is at least the size in bytes of the 10162pointee. ``!nontemporal`` does not have any defined semantics for atomic stores. 10163 10164The optional constant ``align`` argument specifies the alignment of the 10165operation (that is, the alignment of the memory address). A value of 0 10166or an omitted ``align`` argument means that the operation has the ABI 10167alignment for the target. It is the responsibility of the code emitter 10168to ensure that the alignment information is correct. Overestimating the 10169alignment results in undefined behavior. Underestimating the 10170alignment may produce less efficient code. An alignment of 1 is always 10171safe. The maximum possible alignment is ``1 << 32``. An alignment 10172value higher than the size of the stored type implies memory up to the 10173alignment value bytes can be stored to without trapping in the default 10174address space. Storing to the higher bytes however may result in data 10175races if another thread can access the same address. Introducing a 10176data race is not allowed. Storing to the extra bytes is not allowed 10177even in situations where a data race is known to not exist if the 10178function has the ``sanitize_address`` attribute. 10179 10180The optional ``!nontemporal`` metadata must reference a single metadata 10181name ``<nontemp_node>`` corresponding to a metadata node with one ``i32`` entry 10182of value 1. The existence of the ``!nontemporal`` metadata on the instruction 10183tells the optimizer and code generator that this load is not expected to 10184be reused in the cache. The code generator may select special 10185instructions to save cache bandwidth, such as the ``MOVNT`` instruction on 10186x86. 10187 10188The optional ``!invariant.group`` metadata must reference a 10189single metadata name ``<empty_node>``. See ``invariant.group`` metadata. 10190 10191Semantics: 10192"""""""""" 10193 10194The contents of memory are updated to contain ``<value>`` at the 10195location specified by the ``<pointer>`` operand. If ``<value>`` is 10196of scalar type then the number of bytes written does not exceed the 10197minimum number of bytes needed to hold all bits of the type. For 10198example, storing an ``i24`` writes at most three bytes. When writing a 10199value of a type like ``i20`` with a size that is not an integral number 10200of bytes, it is unspecified what happens to the extra bits that do not 10201belong to the type, but they will typically be overwritten. 10202If ``<value>`` is of aggregate type, padding is filled with 10203:ref:`undef <undefvalues>`. 10204If ``<pointer>`` is not a well-defined value, the behavior is undefined. 10205 10206Example: 10207"""""""" 10208 10209.. code-block:: llvm 10210 10211 %ptr = alloca i32 ; yields i32*:ptr 10212 store i32 3, i32* %ptr ; yields void 10213 %val = load i32, i32* %ptr ; yields i32:val = i32 3 10214 10215.. _i_fence: 10216 10217'``fence``' Instruction 10218^^^^^^^^^^^^^^^^^^^^^^^ 10219 10220Syntax: 10221""""""" 10222 10223:: 10224 10225 fence [syncscope("<target-scope>")] <ordering> ; yields void 10226 10227Overview: 10228""""""""" 10229 10230The '``fence``' instruction is used to introduce happens-before edges 10231between operations. 10232 10233Arguments: 10234"""""""""" 10235 10236'``fence``' instructions take an :ref:`ordering <ordering>` argument which 10237defines what *synchronizes-with* edges they add. They can only be given 10238``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings. 10239 10240Semantics: 10241"""""""""" 10242 10243A fence A which has (at least) ``release`` ordering semantics 10244*synchronizes with* a fence B with (at least) ``acquire`` ordering 10245semantics if and only if there exist atomic operations X and Y, both 10246operating on some atomic object M, such that A is sequenced before X, X 10247modifies M (either directly or through some side effect of a sequence 10248headed by X), Y is sequenced before B, and Y observes M. This provides a 10249*happens-before* dependency between A and B. Rather than an explicit 10250``fence``, one (but not both) of the atomic operations X or Y might 10251provide a ``release`` or ``acquire`` (resp.) ordering constraint and 10252still *synchronize-with* the explicit ``fence`` and establish the 10253*happens-before* edge. 10254 10255A ``fence`` which has ``seq_cst`` ordering, in addition to having both 10256``acquire`` and ``release`` semantics specified above, participates in 10257the global program order of other ``seq_cst`` operations and/or fences. 10258 10259A ``fence`` instruction can also take an optional 10260":ref:`syncscope <syncscope>`" argument. 10261 10262Example: 10263"""""""" 10264 10265.. code-block:: text 10266 10267 fence acquire ; yields void 10268 fence syncscope("singlethread") seq_cst ; yields void 10269 fence syncscope("agent") seq_cst ; yields void 10270 10271.. _i_cmpxchg: 10272 10273'``cmpxchg``' Instruction 10274^^^^^^^^^^^^^^^^^^^^^^^^^ 10275 10276Syntax: 10277""""""" 10278 10279:: 10280 10281 cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering>[, align <alignment>] ; yields { ty, i1 } 10282 10283Overview: 10284""""""""" 10285 10286The '``cmpxchg``' instruction is used to atomically modify memory. It 10287loads a value in memory and compares it to a given value. If they are 10288equal, it tries to store a new value into the memory. 10289 10290Arguments: 10291"""""""""" 10292 10293There are three arguments to the '``cmpxchg``' instruction: an address 10294to operate on, a value to compare to the value currently be at that 10295address, and a new value to place at that address if the compared values 10296are equal. The type of '<cmp>' must be an integer or pointer type whose 10297bit width is a power of two greater than or equal to eight and less 10298than or equal to a target-specific size limit. '<cmp>' and '<new>' must 10299have the same type, and the type of '<pointer>' must be a pointer to 10300that type. If the ``cmpxchg`` is marked as ``volatile``, then the 10301optimizer is not allowed to modify the number or order of execution of 10302this ``cmpxchg`` with other :ref:`volatile operations <volatile>`. 10303 10304The success and failure :ref:`ordering <ordering>` arguments specify how this 10305``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters 10306must be at least ``monotonic``, the failure ordering cannot be either 10307``release`` or ``acq_rel``. 10308 10309A ``cmpxchg`` instruction can also take an optional 10310":ref:`syncscope <syncscope>`" argument. 10311 10312The instruction can take an optional ``align`` attribute. 10313The alignment must be a power of two greater or equal to the size of the 10314`<value>` type. If unspecified, the alignment is assumed to be equal to the 10315size of the '<value>' type. Note that this default alignment assumption is 10316different from the alignment used for the load/store instructions when align 10317isn't specified. 10318 10319The pointer passed into cmpxchg must have alignment greater than or 10320equal to the size in memory of the operand. 10321 10322Semantics: 10323"""""""""" 10324 10325The contents of memory at the location specified by the '``<pointer>``' operand 10326is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is 10327written to the location. The original value at the location is returned, 10328together with a flag indicating success (true) or failure (false). 10329 10330If the cmpxchg operation is marked as ``weak`` then a spurious failure is 10331permitted: the operation may not write ``<new>`` even if the comparison 10332matched. 10333 10334If the cmpxchg operation is strong (the default), the i1 value is 1 if and only 10335if the value loaded equals ``cmp``. 10336 10337A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of 10338identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic 10339load with an ordering parameter determined the second ordering parameter. 10340 10341Example: 10342"""""""" 10343 10344.. code-block:: llvm 10345 10346 entry: 10347 %orig = load atomic i32, i32* %ptr unordered, align 4 ; yields i32 10348 br label %loop 10349 10350 loop: 10351 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop] 10352 %squared = mul i32 %cmp, %cmp 10353 %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 } 10354 %value_loaded = extractvalue { i32, i1 } %val_success, 0 10355 %success = extractvalue { i32, i1 } %val_success, 1 10356 br i1 %success, label %done, label %loop 10357 10358 done: 10359 ... 10360 10361.. _i_atomicrmw: 10362 10363'``atomicrmw``' Instruction 10364^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10365 10366Syntax: 10367""""""" 10368 10369:: 10370 10371 atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering>[, align <alignment>] ; yields ty 10372 10373Overview: 10374""""""""" 10375 10376The '``atomicrmw``' instruction is used to atomically modify memory. 10377 10378Arguments: 10379"""""""""" 10380 10381There are three arguments to the '``atomicrmw``' instruction: an 10382operation to apply, an address whose value to modify, an argument to the 10383operation. The operation must be one of the following keywords: 10384 10385- xchg 10386- add 10387- sub 10388- and 10389- nand 10390- or 10391- xor 10392- max 10393- min 10394- umax 10395- umin 10396- fadd 10397- fsub 10398- fmax 10399- fmin 10400 10401For most of these operations, the type of '<value>' must be an integer 10402type whose bit width is a power of two greater than or equal to eight 10403and less than or equal to a target-specific size limit. For xchg, this 10404may also be a floating point or a pointer type with the same size constraints 10405as integers. For fadd/fsub/fmax/fmin, this must be a floating point type. The 10406type of the '``<pointer>``' operand must be a pointer to that type. If 10407the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not 10408allowed to modify the number or order of execution of this 10409``atomicrmw`` with other :ref:`volatile operations <volatile>`. 10410 10411The instruction can take an optional ``align`` attribute. 10412The alignment must be a power of two greater or equal to the size of the 10413`<value>` type. If unspecified, the alignment is assumed to be equal to the 10414size of the '<value>' type. Note that this default alignment assumption is 10415different from the alignment used for the load/store instructions when align 10416isn't specified. 10417 10418A ``atomicrmw`` instruction can also take an optional 10419":ref:`syncscope <syncscope>`" argument. 10420 10421Semantics: 10422"""""""""" 10423 10424The contents of memory at the location specified by the '``<pointer>``' 10425operand are atomically read, modified, and written back. The original 10426value at the location is returned. The modification is specified by the 10427operation argument: 10428 10429- xchg: ``*ptr = val`` 10430- add: ``*ptr = *ptr + val`` 10431- sub: ``*ptr = *ptr - val`` 10432- and: ``*ptr = *ptr & val`` 10433- nand: ``*ptr = ~(*ptr & val)`` 10434- or: ``*ptr = *ptr | val`` 10435- xor: ``*ptr = *ptr ^ val`` 10436- max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison) 10437- min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison) 10438- umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned comparison) 10439- umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned comparison) 10440- fadd: ``*ptr = *ptr + val`` (using floating point arithmetic) 10441- fsub: ``*ptr = *ptr - val`` (using floating point arithmetic) 10442- fmax: ``*ptr = maxnum(*ptr, val)`` (match the `llvm.maxnum.*`` intrinsic) 10443- fmin: ``*ptr = minnum(*ptr, val)`` (match the `llvm.minnum.*`` intrinsic) 10444 10445Example: 10446"""""""" 10447 10448.. code-block:: llvm 10449 10450 %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32 10451 10452.. _i_getelementptr: 10453 10454'``getelementptr``' Instruction 10455^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10456 10457Syntax: 10458""""""" 10459 10460:: 10461 10462 <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}* 10463 <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}* 10464 <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx> 10465 10466Overview: 10467""""""""" 10468 10469The '``getelementptr``' instruction is used to get the address of a 10470subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs 10471address calculation only and does not access memory. The instruction can also 10472be used to calculate a vector of such addresses. 10473 10474Arguments: 10475"""""""""" 10476 10477The first argument is always a type used as the basis for the calculations. 10478The second argument is always a pointer or a vector of pointers, and is the 10479base address to start from. The remaining arguments are indices 10480that indicate which of the elements of the aggregate object are indexed. 10481The interpretation of each index is dependent on the type being indexed 10482into. The first index always indexes the pointer value given as the 10483second argument, the second index indexes a value of the type pointed to 10484(not necessarily the value directly pointed to, since the first index 10485can be non-zero), etc. The first type indexed into must be a pointer 10486value, subsequent types can be arrays, vectors, and structs. Note that 10487subsequent types being indexed into can never be pointers, since that 10488would require loading the pointer before continuing calculation. 10489 10490The type of each index argument depends on the type it is indexing into. 10491When indexing into a (optionally packed) structure, only ``i32`` integer 10492**constants** are allowed (when using a vector of indices they must all 10493be the **same** ``i32`` integer constant). When indexing into an array, 10494pointer or vector, integers of any width are allowed, and they are not 10495required to be constant. These integers are treated as signed values 10496where relevant. 10497 10498For example, let's consider a C code fragment and how it gets compiled 10499to LLVM: 10500 10501.. code-block:: c 10502 10503 struct RT { 10504 char A; 10505 int B[10][20]; 10506 char C; 10507 }; 10508 struct ST { 10509 int X; 10510 double Y; 10511 struct RT Z; 10512 }; 10513 10514 int *foo(struct ST *s) { 10515 return &s[1].Z.B[5][13]; 10516 } 10517 10518The LLVM code generated by Clang is: 10519 10520.. code-block:: llvm 10521 10522 %struct.RT = type { i8, [10 x [20 x i32]], i8 } 10523 %struct.ST = type { i32, double, %struct.RT } 10524 10525 define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp { 10526 entry: 10527 %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13 10528 ret i32* %arrayidx 10529 } 10530 10531Semantics: 10532"""""""""" 10533 10534In the example above, the first index is indexing into the 10535'``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``' 10536= '``{ i32, double, %struct.RT }``' type, a structure. The second index 10537indexes into the third element of the structure, yielding a 10538'``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another 10539structure. The third index indexes into the second element of the 10540structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two 10541dimensions of the array are subscripted into, yielding an '``i32``' 10542type. The '``getelementptr``' instruction returns a pointer to this 10543element, thus computing a value of '``i32*``' type. 10544 10545Note that it is perfectly legal to index partially through a structure, 10546returning a pointer to an inner element. Because of this, the LLVM code 10547for the given testcase is equivalent to: 10548 10549.. code-block:: llvm 10550 10551 define i32* @foo(%struct.ST* %s) { 10552 %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1 10553 %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2 10554 %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3 10555 %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4 10556 %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5 10557 ret i32* %t5 10558 } 10559 10560If the ``inbounds`` keyword is present, the result value of the 10561``getelementptr`` is a :ref:`poison value <poisonvalues>` if one of the 10562following rules is violated: 10563 10564* The base pointer has an *in bounds* address of an allocated object, which 10565 means that it points into an allocated object, or to its end. The only 10566 *in bounds* address for a null pointer in the default address-space is the 10567 null pointer itself. 10568* If the type of an index is larger than the pointer index type, the 10569 truncation to the pointer index type preserves the signed value. 10570* The multiplication of an index by the type size does not wrap the pointer 10571 index type in a signed sense (``nsw``). 10572* The successive addition of offsets (without adding the base address) does 10573 not wrap the pointer index type in a signed sense (``nsw``). 10574* The successive addition of the current address, interpreted as an unsigned 10575 number, and an offset, interpreted as a signed number, does not wrap the 10576 unsigned address space and remains *in bounds* of the allocated object. 10577 As a corollary, if the added offset is non-negative, the addition does not 10578 wrap in an unsigned sense (``nuw``). 10579* In cases where the base is a vector of pointers, the ``inbounds`` keyword 10580 applies to each of the computations element-wise. 10581 10582These rules are based on the assumption that no allocated object may cross 10583the unsigned address space boundary, and no allocated object may be larger 10584than half the pointer index type space. 10585 10586If the ``inbounds`` keyword is not present, the offsets are added to the 10587base address with silently-wrapping two's complement arithmetic. If the 10588offsets have a different width from the pointer, they are sign-extended 10589or truncated to the width of the pointer. The result value of the 10590``getelementptr`` may be outside the object pointed to by the base 10591pointer. The result value may not necessarily be used to access memory 10592though, even if it happens to point into allocated storage. See the 10593:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more 10594information. 10595 10596If the ``inrange`` keyword is present before any index, loading from or 10597storing to any pointer derived from the ``getelementptr`` has undefined 10598behavior if the load or store would access memory outside of the bounds of 10599the element selected by the index marked as ``inrange``. The result of a 10600pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations 10601involving memory) involving a pointer derived from a ``getelementptr`` with 10602the ``inrange`` keyword is undefined, with the exception of comparisons 10603in the case where both operands are in the range of the element selected 10604by the ``inrange`` keyword, inclusive of the address one past the end of 10605that element. Note that the ``inrange`` keyword is currently only allowed 10606in constant ``getelementptr`` expressions. 10607 10608The getelementptr instruction is often confusing. For some more insight 10609into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`. 10610 10611Example: 10612"""""""" 10613 10614.. code-block:: llvm 10615 10616 ; yields [12 x i8]*:aptr 10617 %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1 10618 ; yields i8*:vptr 10619 %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1 10620 ; yields i8*:eptr 10621 %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1 10622 ; yields i32*:iptr 10623 %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0 10624 10625Vector of pointers: 10626""""""""""""""""""" 10627 10628The ``getelementptr`` returns a vector of pointers, instead of a single address, 10629when one or more of its arguments is a vector. In such cases, all vector 10630arguments should have the same number of elements, and every scalar argument 10631will be effectively broadcast into a vector during address calculation. 10632 10633.. code-block:: llvm 10634 10635 ; All arguments are vectors: 10636 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8) 10637 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets 10638 10639 ; Add the same scalar offset to each pointer of a vector: 10640 ; A[i] = ptrs[i] + offset*sizeof(i8) 10641 %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset 10642 10643 ; Add distinct offsets to the same pointer: 10644 ; A[i] = ptr + offsets[i]*sizeof(i8) 10645 %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets 10646 10647 ; In all cases described above the type of the result is <4 x i8*> 10648 10649The two following instructions are equivalent: 10650 10651.. code-block:: llvm 10652 10653 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1, 10654 <4 x i32> <i32 2, i32 2, i32 2, i32 2>, 10655 <4 x i32> <i32 1, i32 1, i32 1, i32 1>, 10656 <4 x i32> %ind4, 10657 <4 x i64> <i64 13, i64 13, i64 13, i64 13> 10658 10659 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1, 10660 i32 2, i32 1, <4 x i32> %ind4, i64 13 10661 10662Let's look at the C code, where the vector version of ``getelementptr`` 10663makes sense: 10664 10665.. code-block:: c 10666 10667 // Let's assume that we vectorize the following loop: 10668 double *A, *B; int *C; 10669 for (int i = 0; i < size; ++i) { 10670 A[i] = B[C[i]]; 10671 } 10672 10673.. code-block:: llvm 10674 10675 ; get pointers for 8 elements from array B 10676 %ptrs = getelementptr double, double* %B, <8 x i32> %C 10677 ; load 8 elements from array B into A 10678 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x double*> %ptrs, 10679 i32 8, <8 x i1> %mask, <8 x double> %passthru) 10680 10681Conversion Operations 10682--------------------- 10683 10684The instructions in this category are the conversion instructions 10685(casting) which all take a single operand and a type. They perform 10686various bit conversions on the operand. 10687 10688.. _i_trunc: 10689 10690'``trunc .. to``' Instruction 10691^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10692 10693Syntax: 10694""""""" 10695 10696:: 10697 10698 <result> = trunc <ty> <value> to <ty2> ; yields ty2 10699 10700Overview: 10701""""""""" 10702 10703The '``trunc``' instruction truncates its operand to the type ``ty2``. 10704 10705Arguments: 10706"""""""""" 10707 10708The '``trunc``' instruction takes a value to trunc, and a type to trunc 10709it to. Both types must be of :ref:`integer <t_integer>` types, or vectors 10710of the same number of integers. The bit size of the ``value`` must be 10711larger than the bit size of the destination type, ``ty2``. Equal sized 10712types are not allowed. 10713 10714Semantics: 10715"""""""""" 10716 10717The '``trunc``' instruction truncates the high order bits in ``value`` 10718and converts the remaining bits to ``ty2``. Since the source size must 10719be larger than the destination size, ``trunc`` cannot be a *no-op cast*. 10720It will always truncate bits. 10721 10722Example: 10723"""""""" 10724 10725.. code-block:: llvm 10726 10727 %X = trunc i32 257 to i8 ; yields i8:1 10728 %Y = trunc i32 123 to i1 ; yields i1:true 10729 %Z = trunc i32 122 to i1 ; yields i1:false 10730 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7> 10731 10732.. _i_zext: 10733 10734'``zext .. to``' Instruction 10735^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10736 10737Syntax: 10738""""""" 10739 10740:: 10741 10742 <result> = zext <ty> <value> to <ty2> ; yields ty2 10743 10744Overview: 10745""""""""" 10746 10747The '``zext``' instruction zero extends its operand to type ``ty2``. 10748 10749Arguments: 10750"""""""""" 10751 10752The '``zext``' instruction takes a value to cast, and a type to cast it 10753to. Both types must be of :ref:`integer <t_integer>` types, or vectors of 10754the same number of integers. The bit size of the ``value`` must be 10755smaller than the bit size of the destination type, ``ty2``. 10756 10757Semantics: 10758"""""""""" 10759 10760The ``zext`` fills the high order bits of the ``value`` with zero bits 10761until it reaches the size of the destination type, ``ty2``. 10762 10763When zero extending from i1, the result will always be either 0 or 1. 10764 10765Example: 10766"""""""" 10767 10768.. code-block:: llvm 10769 10770 %X = zext i32 257 to i64 ; yields i64:257 10771 %Y = zext i1 true to i32 ; yields i32:1 10772 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 10773 10774.. _i_sext: 10775 10776'``sext .. to``' Instruction 10777^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10778 10779Syntax: 10780""""""" 10781 10782:: 10783 10784 <result> = sext <ty> <value> to <ty2> ; yields ty2 10785 10786Overview: 10787""""""""" 10788 10789The '``sext``' sign extends ``value`` to the type ``ty2``. 10790 10791Arguments: 10792"""""""""" 10793 10794The '``sext``' instruction takes a value to cast, and a type to cast it 10795to. Both types must be of :ref:`integer <t_integer>` types, or vectors of 10796the same number of integers. The bit size of the ``value`` must be 10797smaller than the bit size of the destination type, ``ty2``. 10798 10799Semantics: 10800"""""""""" 10801 10802The '``sext``' instruction performs a sign extension by copying the sign 10803bit (highest order bit) of the ``value`` until it reaches the bit size 10804of the type ``ty2``. 10805 10806When sign extending from i1, the extension always results in -1 or 0. 10807 10808Example: 10809"""""""" 10810 10811.. code-block:: llvm 10812 10813 %X = sext i8 -1 to i16 ; yields i16 :65535 10814 %Y = sext i1 true to i32 ; yields i32:-1 10815 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 10816 10817'``fptrunc .. to``' Instruction 10818^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10819 10820Syntax: 10821""""""" 10822 10823:: 10824 10825 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2 10826 10827Overview: 10828""""""""" 10829 10830The '``fptrunc``' instruction truncates ``value`` to type ``ty2``. 10831 10832Arguments: 10833"""""""""" 10834 10835The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>` 10836value to cast and a :ref:`floating-point <t_floating>` type to cast it to. 10837The size of ``value`` must be larger than the size of ``ty2``. This 10838implies that ``fptrunc`` cannot be used to make a *no-op cast*. 10839 10840Semantics: 10841"""""""""" 10842 10843The '``fptrunc``' instruction casts a ``value`` from a larger 10844:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 10845<t_floating>` type. 10846This instruction is assumed to execute in the default :ref:`floating-point 10847environment <floatenv>`. 10848 10849Example: 10850"""""""" 10851 10852.. code-block:: llvm 10853 10854 %X = fptrunc double 16777217.0 to float ; yields float:16777216.0 10855 %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity 10856 10857'``fpext .. to``' Instruction 10858^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10859 10860Syntax: 10861""""""" 10862 10863:: 10864 10865 <result> = fpext <ty> <value> to <ty2> ; yields ty2 10866 10867Overview: 10868""""""""" 10869 10870The '``fpext``' extends a floating-point ``value`` to a larger floating-point 10871value. 10872 10873Arguments: 10874"""""""""" 10875 10876The '``fpext``' instruction takes a :ref:`floating-point <t_floating>` 10877``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it 10878to. The source type must be smaller than the destination type. 10879 10880Semantics: 10881"""""""""" 10882 10883The '``fpext``' instruction extends the ``value`` from a smaller 10884:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point 10885<t_floating>` type. The ``fpext`` cannot be used to make a 10886*no-op cast* because it always changes bits. Use ``bitcast`` to make a 10887*no-op cast* for a floating-point cast. 10888 10889Example: 10890"""""""" 10891 10892.. code-block:: llvm 10893 10894 %X = fpext float 3.125 to double ; yields double:3.125000e+00 10895 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000 10896 10897'``fptoui .. to``' Instruction 10898^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10899 10900Syntax: 10901""""""" 10902 10903:: 10904 10905 <result> = fptoui <ty> <value> to <ty2> ; yields ty2 10906 10907Overview: 10908""""""""" 10909 10910The '``fptoui``' converts a floating-point ``value`` to its unsigned 10911integer equivalent of type ``ty2``. 10912 10913Arguments: 10914"""""""""" 10915 10916The '``fptoui``' instruction takes a value to cast, which must be a 10917scalar or vector :ref:`floating-point <t_floating>` value, and a type to 10918cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 10919``ty`` is a vector floating-point type, ``ty2`` must be a vector integer 10920type with the same number of elements as ``ty`` 10921 10922Semantics: 10923"""""""""" 10924 10925The '``fptoui``' instruction converts its :ref:`floating-point 10926<t_floating>` operand into the nearest (rounding towards zero) 10927unsigned integer value. If the value cannot fit in ``ty2``, the result 10928is a :ref:`poison value <poisonvalues>`. 10929 10930Example: 10931"""""""" 10932 10933.. code-block:: llvm 10934 10935 %X = fptoui double 123.0 to i32 ; yields i32:123 10936 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1 10937 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1 10938 10939'``fptosi .. to``' Instruction 10940^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10941 10942Syntax: 10943""""""" 10944 10945:: 10946 10947 <result> = fptosi <ty> <value> to <ty2> ; yields ty2 10948 10949Overview: 10950""""""""" 10951 10952The '``fptosi``' instruction converts :ref:`floating-point <t_floating>` 10953``value`` to type ``ty2``. 10954 10955Arguments: 10956"""""""""" 10957 10958The '``fptosi``' instruction takes a value to cast, which must be a 10959scalar or vector :ref:`floating-point <t_floating>` value, and a type to 10960cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 10961``ty`` is a vector floating-point type, ``ty2`` must be a vector integer 10962type with the same number of elements as ``ty`` 10963 10964Semantics: 10965"""""""""" 10966 10967The '``fptosi``' instruction converts its :ref:`floating-point 10968<t_floating>` operand into the nearest (rounding towards zero) 10969signed integer value. If the value cannot fit in ``ty2``, the result 10970is a :ref:`poison value <poisonvalues>`. 10971 10972Example: 10973"""""""" 10974 10975.. code-block:: llvm 10976 10977 %X = fptosi double -123.0 to i32 ; yields i32:-123 10978 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1 10979 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1 10980 10981'``uitofp .. to``' Instruction 10982^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10983 10984Syntax: 10985""""""" 10986 10987:: 10988 10989 <result> = uitofp <ty> <value> to <ty2> ; yields ty2 10990 10991Overview: 10992""""""""" 10993 10994The '``uitofp``' instruction regards ``value`` as an unsigned integer 10995and converts that value to the ``ty2`` type. 10996 10997Arguments: 10998"""""""""" 10999 11000The '``uitofp``' instruction takes a value to cast, which must be a 11001scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 11002``ty2``, which must be an :ref:`floating-point <t_floating>` type. If 11003``ty`` is a vector integer type, ``ty2`` must be a vector floating-point 11004type with the same number of elements as ``ty`` 11005 11006Semantics: 11007"""""""""" 11008 11009The '``uitofp``' instruction interprets its operand as an unsigned 11010integer quantity and converts it to the corresponding floating-point 11011value. If the value cannot be exactly represented, it is rounded using 11012the default rounding mode. 11013 11014 11015Example: 11016"""""""" 11017 11018.. code-block:: llvm 11019 11020 %X = uitofp i32 257 to float ; yields float:257.0 11021 %Y = uitofp i8 -1 to double ; yields double:255.0 11022 11023'``sitofp .. to``' Instruction 11024^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11025 11026Syntax: 11027""""""" 11028 11029:: 11030 11031 <result> = sitofp <ty> <value> to <ty2> ; yields ty2 11032 11033Overview: 11034""""""""" 11035 11036The '``sitofp``' instruction regards ``value`` as a signed integer and 11037converts that value to the ``ty2`` type. 11038 11039Arguments: 11040"""""""""" 11041 11042The '``sitofp``' instruction takes a value to cast, which must be a 11043scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 11044``ty2``, which must be an :ref:`floating-point <t_floating>` type. If 11045``ty`` is a vector integer type, ``ty2`` must be a vector floating-point 11046type with the same number of elements as ``ty`` 11047 11048Semantics: 11049"""""""""" 11050 11051The '``sitofp``' instruction interprets its operand as a signed integer 11052quantity and converts it to the corresponding floating-point value. If the 11053value cannot be exactly represented, it is rounded using the default rounding 11054mode. 11055 11056Example: 11057"""""""" 11058 11059.. code-block:: llvm 11060 11061 %X = sitofp i32 257 to float ; yields float:257.0 11062 %Y = sitofp i8 -1 to double ; yields double:-1.0 11063 11064.. _i_ptrtoint: 11065 11066'``ptrtoint .. to``' Instruction 11067^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11068 11069Syntax: 11070""""""" 11071 11072:: 11073 11074 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2 11075 11076Overview: 11077""""""""" 11078 11079The '``ptrtoint``' instruction converts the pointer or a vector of 11080pointers ``value`` to the integer (or vector of integers) type ``ty2``. 11081 11082Arguments: 11083"""""""""" 11084 11085The '``ptrtoint``' instruction takes a ``value`` to cast, which must be 11086a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a 11087type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or 11088a vector of integers type. 11089 11090Semantics: 11091"""""""""" 11092 11093The '``ptrtoint``' instruction converts ``value`` to integer type 11094``ty2`` by interpreting the pointer value as an integer and either 11095truncating or zero extending that value to the size of the integer type. 11096If ``value`` is smaller than ``ty2`` then a zero extension is done. If 11097``value`` is larger than ``ty2`` then a truncation is done. If they are 11098the same size, then nothing is done (*no-op cast*) other than a type 11099change. 11100 11101Example: 11102"""""""" 11103 11104.. code-block:: llvm 11105 11106 %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture 11107 %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture 11108 %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture 11109 11110.. _i_inttoptr: 11111 11112'``inttoptr .. to``' Instruction 11113^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11114 11115Syntax: 11116""""""" 11117 11118:: 11119 11120 <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>] ; yields ty2 11121 11122Overview: 11123""""""""" 11124 11125The '``inttoptr``' instruction converts an integer ``value`` to a 11126pointer type, ``ty2``. 11127 11128Arguments: 11129"""""""""" 11130 11131The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to 11132cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>` 11133type. 11134 11135The optional ``!dereferenceable`` metadata must reference a single metadata 11136name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 11137entry. 11138See ``dereferenceable`` metadata. 11139 11140The optional ``!dereferenceable_or_null`` metadata must reference a single 11141metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 11142``i64`` entry. 11143See ``dereferenceable_or_null`` metadata. 11144 11145Semantics: 11146"""""""""" 11147 11148The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by 11149applying either a zero extension or a truncation depending on the size 11150of the integer ``value``. If ``value`` is larger than the size of a 11151pointer then a truncation is done. If ``value`` is smaller than the size 11152of a pointer then a zero extension is done. If they are the same size, 11153nothing is done (*no-op cast*). 11154 11155Example: 11156"""""""" 11157 11158.. code-block:: llvm 11159 11160 %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture 11161 %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture 11162 %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture 11163 %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers 11164 11165.. _i_bitcast: 11166 11167'``bitcast .. to``' Instruction 11168^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11169 11170Syntax: 11171""""""" 11172 11173:: 11174 11175 <result> = bitcast <ty> <value> to <ty2> ; yields ty2 11176 11177Overview: 11178""""""""" 11179 11180The '``bitcast``' instruction converts ``value`` to type ``ty2`` without 11181changing any bits. 11182 11183Arguments: 11184"""""""""" 11185 11186The '``bitcast``' instruction takes a value to cast, which must be a 11187non-aggregate first class value, and a type to cast it to, which must 11188also be a non-aggregate :ref:`first class <t_firstclass>` type. The 11189bit sizes of ``value`` and the destination type, ``ty2``, must be 11190identical. If the source type is a pointer, the destination type must 11191also be a pointer of the same size. This instruction supports bitwise 11192conversion of vectors to integers and to vectors of other types (as 11193long as they have the same size). 11194 11195Semantics: 11196"""""""""" 11197 11198The '``bitcast``' instruction converts ``value`` to type ``ty2``. It 11199is always a *no-op cast* because no bits change with this 11200conversion. The conversion is done as if the ``value`` had been stored 11201to memory and read back as type ``ty2``. Pointer (or vector of 11202pointers) types may only be converted to other pointer (or vector of 11203pointers) types with the same address space through this instruction. 11204To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>` 11205or :ref:`ptrtoint <i_ptrtoint>` instructions first. 11206 11207There is a caveat for bitcasts involving vector types in relation to 11208endianess. For example ``bitcast <2 x i8> <value> to i16`` puts element zero 11209of the vector in the least significant bits of the i16 for little-endian while 11210element zero ends up in the most significant bits for big-endian. 11211 11212Example: 11213"""""""" 11214 11215.. code-block:: text 11216 11217 %X = bitcast i8 255 to i8 ; yields i8 :-1 11218 %Y = bitcast i32* %x to i16* ; yields i16*:%x 11219 %Z = bitcast <2 x i32> %V to i64; ; yields i64: %V (depends on endianess) 11220 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*> 11221 11222.. _i_addrspacecast: 11223 11224'``addrspacecast .. to``' Instruction 11225^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11226 11227Syntax: 11228""""""" 11229 11230:: 11231 11232 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2 11233 11234Overview: 11235""""""""" 11236 11237The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in 11238address space ``n`` to type ``pty2`` in address space ``m``. 11239 11240Arguments: 11241"""""""""" 11242 11243The '``addrspacecast``' instruction takes a pointer or vector of pointer value 11244to cast and a pointer type to cast it to, which must have a different 11245address space. 11246 11247Semantics: 11248"""""""""" 11249 11250The '``addrspacecast``' instruction converts the pointer value 11251``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex 11252value modification, depending on the target and the address space 11253pair. Pointer conversions within the same address space must be 11254performed with the ``bitcast`` instruction. Note that if the address space 11255conversion is legal then both result and operand refer to the same memory 11256location. 11257 11258Example: 11259"""""""" 11260 11261.. code-block:: llvm 11262 11263 %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x 11264 %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y 11265 %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*> ; yields <4 x float addrspace(3)*>:%z 11266 11267.. _otherops: 11268 11269Other Operations 11270---------------- 11271 11272The instructions in this category are the "miscellaneous" instructions, 11273which defy better classification. 11274 11275.. _i_icmp: 11276 11277'``icmp``' Instruction 11278^^^^^^^^^^^^^^^^^^^^^^ 11279 11280Syntax: 11281""""""" 11282 11283:: 11284 11285 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 11286 11287Overview: 11288""""""""" 11289 11290The '``icmp``' instruction returns a boolean value or a vector of 11291boolean values based on comparison of its two integer, integer vector, 11292pointer, or pointer vector operands. 11293 11294Arguments: 11295"""""""""" 11296 11297The '``icmp``' instruction takes three operands. The first operand is 11298the condition code indicating the kind of comparison to perform. It is 11299not a value, just a keyword. The possible condition codes are: 11300 11301.. _icmp_md_cc: 11302 11303#. ``eq``: equal 11304#. ``ne``: not equal 11305#. ``ugt``: unsigned greater than 11306#. ``uge``: unsigned greater or equal 11307#. ``ult``: unsigned less than 11308#. ``ule``: unsigned less or equal 11309#. ``sgt``: signed greater than 11310#. ``sge``: signed greater or equal 11311#. ``slt``: signed less than 11312#. ``sle``: signed less or equal 11313 11314The remaining two arguments must be :ref:`integer <t_integer>` or 11315:ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They 11316must also be identical types. 11317 11318Semantics: 11319"""""""""" 11320 11321The '``icmp``' compares ``op1`` and ``op2`` according to the condition 11322code given as ``cond``. The comparison performed always yields either an 11323:ref:`i1 <t_integer>` or vector of ``i1`` result, as follows: 11324 11325.. _icmp_md_cc_sem: 11326 11327#. ``eq``: yields ``true`` if the operands are equal, ``false`` 11328 otherwise. No sign interpretation is necessary or performed. 11329#. ``ne``: yields ``true`` if the operands are unequal, ``false`` 11330 otherwise. No sign interpretation is necessary or performed. 11331#. ``ugt``: interprets the operands as unsigned values and yields 11332 ``true`` if ``op1`` is greater than ``op2``. 11333#. ``uge``: interprets the operands as unsigned values and yields 11334 ``true`` if ``op1`` is greater than or equal to ``op2``. 11335#. ``ult``: interprets the operands as unsigned values and yields 11336 ``true`` if ``op1`` is less than ``op2``. 11337#. ``ule``: interprets the operands as unsigned values and yields 11338 ``true`` if ``op1`` is less than or equal to ``op2``. 11339#. ``sgt``: interprets the operands as signed values and yields ``true`` 11340 if ``op1`` is greater than ``op2``. 11341#. ``sge``: interprets the operands as signed values and yields ``true`` 11342 if ``op1`` is greater than or equal to ``op2``. 11343#. ``slt``: interprets the operands as signed values and yields ``true`` 11344 if ``op1`` is less than ``op2``. 11345#. ``sle``: interprets the operands as signed values and yields ``true`` 11346 if ``op1`` is less than or equal to ``op2``. 11347 11348If the operands are :ref:`pointer <t_pointer>` typed, the pointer values 11349are compared as if they were integers. 11350 11351If the operands are integer vectors, then they are compared element by 11352element. The result is an ``i1`` vector with the same number of elements 11353as the values being compared. Otherwise, the result is an ``i1``. 11354 11355Example: 11356"""""""" 11357 11358.. code-block:: text 11359 11360 <result> = icmp eq i32 4, 5 ; yields: result=false 11361 <result> = icmp ne float* %X, %X ; yields: result=false 11362 <result> = icmp ult i16 4, 5 ; yields: result=true 11363 <result> = icmp sgt i16 4, 5 ; yields: result=false 11364 <result> = icmp ule i16 -4, 5 ; yields: result=false 11365 <result> = icmp sge i16 4, 5 ; yields: result=false 11366 11367.. _i_fcmp: 11368 11369'``fcmp``' Instruction 11370^^^^^^^^^^^^^^^^^^^^^^ 11371 11372Syntax: 11373""""""" 11374 11375:: 11376 11377 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 11378 11379Overview: 11380""""""""" 11381 11382The '``fcmp``' instruction returns a boolean value or vector of boolean 11383values based on comparison of its operands. 11384 11385If the operands are floating-point scalars, then the result type is a 11386boolean (:ref:`i1 <t_integer>`). 11387 11388If the operands are floating-point vectors, then the result type is a 11389vector of boolean with the same number of elements as the operands being 11390compared. 11391 11392Arguments: 11393"""""""""" 11394 11395The '``fcmp``' instruction takes three operands. The first operand is 11396the condition code indicating the kind of comparison to perform. It is 11397not a value, just a keyword. The possible condition codes are: 11398 11399#. ``false``: no comparison, always returns false 11400#. ``oeq``: ordered and equal 11401#. ``ogt``: ordered and greater than 11402#. ``oge``: ordered and greater than or equal 11403#. ``olt``: ordered and less than 11404#. ``ole``: ordered and less than or equal 11405#. ``one``: ordered and not equal 11406#. ``ord``: ordered (no nans) 11407#. ``ueq``: unordered or equal 11408#. ``ugt``: unordered or greater than 11409#. ``uge``: unordered or greater than or equal 11410#. ``ult``: unordered or less than 11411#. ``ule``: unordered or less than or equal 11412#. ``une``: unordered or not equal 11413#. ``uno``: unordered (either nans) 11414#. ``true``: no comparison, always returns true 11415 11416*Ordered* means that neither operand is a QNAN while *unordered* means 11417that either operand may be a QNAN. 11418 11419Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point 11420<t_floating>` type or a :ref:`vector <t_vector>` of floating-point type. 11421They must have identical types. 11422 11423Semantics: 11424"""""""""" 11425 11426The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the 11427condition code given as ``cond``. If the operands are vectors, then the 11428vectors are compared element by element. Each comparison performed 11429always yields an :ref:`i1 <t_integer>` result, as follows: 11430 11431#. ``false``: always yields ``false``, regardless of operands. 11432#. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1`` 11433 is equal to ``op2``. 11434#. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1`` 11435 is greater than ``op2``. 11436#. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1`` 11437 is greater than or equal to ``op2``. 11438#. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1`` 11439 is less than ``op2``. 11440#. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1`` 11441 is less than or equal to ``op2``. 11442#. ``one``: yields ``true`` if both operands are not a QNAN and ``op1`` 11443 is not equal to ``op2``. 11444#. ``ord``: yields ``true`` if both operands are not a QNAN. 11445#. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is 11446 equal to ``op2``. 11447#. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is 11448 greater than ``op2``. 11449#. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is 11450 greater than or equal to ``op2``. 11451#. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is 11452 less than ``op2``. 11453#. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is 11454 less than or equal to ``op2``. 11455#. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is 11456 not equal to ``op2``. 11457#. ``uno``: yields ``true`` if either operand is a QNAN. 11458#. ``true``: always yields ``true``, regardless of operands. 11459 11460The ``fcmp`` instruction can also optionally take any number of 11461:ref:`fast-math flags <fastmath>`, which are optimization hints to enable 11462otherwise unsafe floating-point optimizations. 11463 11464Any set of fast-math flags are legal on an ``fcmp`` instruction, but the 11465only flags that have any effect on its semantics are those that allow 11466assumptions to be made about the values of input arguments; namely 11467``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information. 11468 11469Example: 11470"""""""" 11471 11472.. code-block:: text 11473 11474 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false 11475 <result> = fcmp one float 4.0, 5.0 ; yields: result=true 11476 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true 11477 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false 11478 11479.. _i_phi: 11480 11481'``phi``' Instruction 11482^^^^^^^^^^^^^^^^^^^^^ 11483 11484Syntax: 11485""""""" 11486 11487:: 11488 11489 <result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ... 11490 11491Overview: 11492""""""""" 11493 11494The '``phi``' instruction is used to implement the φ node in the SSA 11495graph representing the function. 11496 11497Arguments: 11498"""""""""" 11499 11500The type of the incoming values is specified with the first type field. 11501After this, the '``phi``' instruction takes a list of pairs as 11502arguments, with one pair for each predecessor basic block of the current 11503block. Only values of :ref:`first class <t_firstclass>` type may be used as 11504the value arguments to the PHI node. Only labels may be used as the 11505label arguments. 11506 11507There must be no non-phi instructions between the start of a basic block 11508and the PHI instructions: i.e. PHI instructions must be first in a basic 11509block. 11510 11511For the purposes of the SSA form, the use of each incoming value is 11512deemed to occur on the edge from the corresponding predecessor block to 11513the current block (but after any definition of an '``invoke``' 11514instruction's return value on the same edge). 11515 11516The optional ``fast-math-flags`` marker indicates that the phi has one 11517or more :ref:`fast-math-flags <fastmath>`. These are optimization hints 11518to enable otherwise unsafe floating-point optimizations. Fast-math-flags 11519are only valid for phis that return a floating-point scalar or vector 11520type, or an array (nested to any depth) of floating-point scalar or vector 11521types. 11522 11523Semantics: 11524"""""""""" 11525 11526At runtime, the '``phi``' instruction logically takes on the value 11527specified by the pair corresponding to the predecessor basic block that 11528executed just prior to the current block. 11529 11530Example: 11531"""""""" 11532 11533.. code-block:: llvm 11534 11535 Loop: ; Infinite loop that counts from 0 on up... 11536 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ] 11537 %nextindvar = add i32 %indvar, 1 11538 br label %Loop 11539 11540.. _i_select: 11541 11542'``select``' Instruction 11543^^^^^^^^^^^^^^^^^^^^^^^^ 11544 11545Syntax: 11546""""""" 11547 11548:: 11549 11550 <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty 11551 11552 selty is either i1 or {<N x i1>} 11553 11554Overview: 11555""""""""" 11556 11557The '``select``' instruction is used to choose one value based on a 11558condition, without IR-level branching. 11559 11560Arguments: 11561"""""""""" 11562 11563The '``select``' instruction requires an 'i1' value or a vector of 'i1' 11564values indicating the condition, and two values of the same :ref:`first 11565class <t_firstclass>` type. 11566 11567#. The optional ``fast-math flags`` marker indicates that the select has one or more 11568 :ref:`fast-math flags <fastmath>`. These are optimization hints to enable 11569 otherwise unsafe floating-point optimizations. Fast-math flags are only valid 11570 for selects that return a floating-point scalar or vector type, or an array 11571 (nested to any depth) of floating-point scalar or vector types. 11572 11573Semantics: 11574"""""""""" 11575 11576If the condition is an i1 and it evaluates to 1, the instruction returns 11577the first value argument; otherwise, it returns the second value 11578argument. 11579 11580If the condition is a vector of i1, then the value arguments must be 11581vectors of the same size, and the selection is done element by element. 11582 11583If the condition is an i1 and the value arguments are vectors of the 11584same size, then an entire vector is selected. 11585 11586Example: 11587"""""""" 11588 11589.. code-block:: llvm 11590 11591 %X = select i1 true, i8 17, i8 42 ; yields i8:17 11592 11593 11594.. _i_freeze: 11595 11596'``freeze``' Instruction 11597^^^^^^^^^^^^^^^^^^^^^^^^ 11598 11599Syntax: 11600""""""" 11601 11602:: 11603 11604 <result> = freeze ty <val> ; yields ty:result 11605 11606Overview: 11607""""""""" 11608 11609The '``freeze``' instruction is used to stop propagation of 11610:ref:`undef <undefvalues>` and :ref:`poison <poisonvalues>` values. 11611 11612Arguments: 11613"""""""""" 11614 11615The '``freeze``' instruction takes a single argument. 11616 11617Semantics: 11618"""""""""" 11619 11620If the argument is ``undef`` or ``poison``, '``freeze``' returns an 11621arbitrary, but fixed, value of type '``ty``'. 11622Otherwise, this instruction is a no-op and returns the input argument. 11623All uses of a value returned by the same '``freeze``' instruction are 11624guaranteed to always observe the same value, while different '``freeze``' 11625instructions may yield different values. 11626 11627While ``undef`` and ``poison`` pointers can be frozen, the result is a 11628non-dereferenceable pointer. See the 11629:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more information. 11630If an aggregate value or vector is frozen, the operand is frozen element-wise. 11631The padding of an aggregate isn't considered, since it isn't visible 11632without storing it into memory and loading it with a different type. 11633 11634 11635Example: 11636"""""""" 11637 11638.. code-block:: text 11639 11640 %w = i32 undef 11641 %x = freeze i32 %w 11642 %y = add i32 %w, %w ; undef 11643 %z = add i32 %x, %x ; even number because all uses of %x observe 11644 ; the same value 11645 %x2 = freeze i32 %w 11646 %cmp = icmp eq i32 %x, %x2 ; can be true or false 11647 11648 ; example with vectors 11649 %v = <2 x i32> <i32 undef, i32 poison> 11650 %a = extractelement <2 x i32> %v, i32 0 ; undef 11651 %b = extractelement <2 x i32> %v, i32 1 ; poison 11652 %add = add i32 %a, %a ; undef 11653 11654 %v.fr = freeze <2 x i32> %v ; element-wise freeze 11655 %d = extractelement <2 x i32> %v.fr, i32 0 ; not undef 11656 %add.f = add i32 %d, %d ; even number 11657 11658 ; branching on frozen value 11659 %poison = add nsw i1 %k, undef ; poison 11660 %c = freeze i1 %poison 11661 br i1 %c, label %foo, label %bar ; non-deterministic branch to %foo or %bar 11662 11663 11664.. _i_call: 11665 11666'``call``' Instruction 11667^^^^^^^^^^^^^^^^^^^^^^ 11668 11669Syntax: 11670""""""" 11671 11672:: 11673 11674 <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)] 11675 <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ] 11676 11677Overview: 11678""""""""" 11679 11680The '``call``' instruction represents a simple function call. 11681 11682Arguments: 11683"""""""""" 11684 11685This instruction requires several arguments: 11686 11687#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers 11688 should perform tail call optimization. The ``tail`` marker is a hint that 11689 `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker 11690 means that the call must be tail call optimized in order for the program to 11691 be correct. The ``musttail`` marker provides these guarantees: 11692 11693 #. The call will not cause unbounded stack growth if it is part of a 11694 recursive cycle in the call graph. 11695 #. Arguments with the :ref:`inalloca <attr_inalloca>` or 11696 :ref:`preallocated <attr_preallocated>` attribute are forwarded in place. 11697 #. If the musttail call appears in a function with the ``"thunk"`` attribute 11698 and the caller and callee both have varargs, than any unprototyped 11699 arguments in register or memory are forwarded to the callee. Similarly, 11700 the return value of the callee is returned to the caller's caller, even 11701 if a void return type is in use. 11702 11703 Both markers imply that the callee does not access allocas from the caller. 11704 The ``tail`` marker additionally implies that the callee does not access 11705 varargs from the caller. Calls marked ``musttail`` must obey the following 11706 additional rules: 11707 11708 - The call must immediately precede a :ref:`ret <i_ret>` instruction, 11709 or a pointer bitcast followed by a ret instruction. 11710 - The ret instruction must return the (possibly bitcasted) value 11711 produced by the call, undef, or void. 11712 - The calling conventions of the caller and callee must match. 11713 - The callee must be varargs iff the caller is varargs. Bitcasting a 11714 non-varargs function to the appropriate varargs type is legal so 11715 long as the non-varargs prefixes obey the other rules. 11716 - The return type must not undergo automatic conversion to an `sret` pointer. 11717 11718 In addition, if the calling convention is not `swifttailcc` or `tailcc`: 11719 11720 - All ABI-impacting function attributes, such as sret, byval, inreg, 11721 returned, and inalloca, must match. 11722 - The caller and callee prototypes must match. Pointer types of parameters 11723 or return types may differ in pointee type, but not in address space. 11724 11725 On the other hand, if the calling convention is `swifttailcc` or `swiftcc`: 11726 11727 - Only these ABI-impacting attributes attributes are allowed: sret, byval, 11728 swiftself, and swiftasync. 11729 - Prototypes are not required to match. 11730 11731 Tail call optimization for calls marked ``tail`` is guaranteed to occur if 11732 the following conditions are met: 11733 11734 - Caller and callee both have the calling convention ``fastcc`` or ``tailcc``. 11735 - The call is in tail position (ret immediately follows call and ret 11736 uses value of call or is void). 11737 - Option ``-tailcallopt`` is enabled, 11738 ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention 11739 is ``tailcc`` 11740 - `Platform-specific constraints are 11741 met. <CodeGenerator.html#tailcallopt>`_ 11742 11743#. The optional ``notail`` marker indicates that the optimizers should not add 11744 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail 11745 call optimization from being performed on the call. 11746 11747#. The optional ``fast-math flags`` marker indicates that the call has one or more 11748 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable 11749 otherwise unsafe floating-point optimizations. Fast-math flags are only valid 11750 for calls that return a floating-point scalar or vector type, or an array 11751 (nested to any depth) of floating-point scalar or vector types. 11752 11753#. The optional "cconv" marker indicates which :ref:`calling 11754 convention <callingconv>` the call should use. If none is 11755 specified, the call defaults to using C calling conventions. The 11756 calling convention of the call must match the calling convention of 11757 the target function, or else the behavior is undefined. 11758#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 11759 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 11760 are valid here. 11761#. The optional addrspace attribute can be used to indicate the address space 11762 of the called function. If it is not specified, the program address space 11763 from the :ref:`datalayout string<langref_datalayout>` will be used. 11764#. '``ty``': the type of the call instruction itself which is also the 11765 type of the return value. Functions that return no value are marked 11766 ``void``. 11767#. '``fnty``': shall be the signature of the function being called. The 11768 argument types must match the types implied by this signature. This 11769 type can be omitted if the function is not varargs. 11770#. '``fnptrval``': An LLVM value containing a pointer to a function to 11771 be called. In most cases, this is a direct function call, but 11772 indirect ``call``'s are just as possible, calling an arbitrary pointer 11773 to function value. 11774#. '``function args``': argument list whose types match the function 11775 signature argument types and parameter attributes. All arguments must 11776 be of :ref:`first class <t_firstclass>` type. If the function signature 11777 indicates the function accepts a variable number of arguments, the 11778 extra arguments can be specified. 11779#. The optional :ref:`function attributes <fnattrs>` list. 11780#. The optional :ref:`operand bundles <opbundles>` list. 11781 11782Semantics: 11783"""""""""" 11784 11785The '``call``' instruction is used to cause control flow to transfer to 11786a specified function, with its incoming arguments bound to the specified 11787values. Upon a '``ret``' instruction in the called function, control 11788flow continues with the instruction after the function call, and the 11789return value of the function is bound to the result argument. 11790 11791Example: 11792"""""""" 11793 11794.. code-block:: llvm 11795 11796 %retval = call i32 @test(i32 %argc) 11797 call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32 11798 %X = tail call i32 @foo() ; yields i32 11799 %Y = tail call fastcc i32 @foo() ; yields i32 11800 call void %foo(i8 signext 97) 11801 11802 %struct.A = type { i32, i8 } 11803 %r = call %struct.A @foo() ; yields { i32, i8 } 11804 %gr = extractvalue %struct.A %r, 0 ; yields i32 11805 %gr1 = extractvalue %struct.A %r, 1 ; yields i8 11806 %Z = call void @foo() noreturn ; indicates that %foo never returns normally 11807 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended 11808 11809llvm treats calls to some functions with names and arguments that match 11810the standard C99 library as being the C99 library functions, and may 11811perform optimizations or generate code for them under that assumption. 11812This is something we'd like to change in the future to provide better 11813support for freestanding environments and non-C-based languages. 11814 11815.. _i_va_arg: 11816 11817'``va_arg``' Instruction 11818^^^^^^^^^^^^^^^^^^^^^^^^ 11819 11820Syntax: 11821""""""" 11822 11823:: 11824 11825 <resultval> = va_arg <va_list*> <arglist>, <argty> 11826 11827Overview: 11828""""""""" 11829 11830The '``va_arg``' instruction is used to access arguments passed through 11831the "variable argument" area of a function call. It is used to implement 11832the ``va_arg`` macro in C. 11833 11834Arguments: 11835"""""""""" 11836 11837This instruction takes a ``va_list*`` value and the type of the 11838argument. It returns a value of the specified argument type and 11839increments the ``va_list`` to point to the next argument. The actual 11840type of ``va_list`` is target specific. 11841 11842Semantics: 11843"""""""""" 11844 11845The '``va_arg``' instruction loads an argument of the specified type 11846from the specified ``va_list`` and causes the ``va_list`` to point to 11847the next argument. For more information, see the variable argument 11848handling :ref:`Intrinsic Functions <int_varargs>`. 11849 11850It is legal for this instruction to be called in a function which does 11851not take a variable number of arguments, for example, the ``vfprintf`` 11852function. 11853 11854``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic 11855function <intrinsics>` because it takes a type as an argument. 11856 11857Example: 11858"""""""" 11859 11860See the :ref:`variable argument processing <int_varargs>` section. 11861 11862Note that the code generator does not yet fully support va\_arg on many 11863targets. Also, it does not currently support va\_arg with aggregate 11864types on any target. 11865 11866.. _i_landingpad: 11867 11868'``landingpad``' Instruction 11869^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11870 11871Syntax: 11872""""""" 11873 11874:: 11875 11876 <resultval> = landingpad <resultty> <clause>+ 11877 <resultval> = landingpad <resultty> cleanup <clause>* 11878 11879 <clause> := catch <type> <value> 11880 <clause> := filter <array constant type> <array constant> 11881 11882Overview: 11883""""""""" 11884 11885The '``landingpad``' instruction is used by `LLVM's exception handling 11886system <ExceptionHandling.html#overview>`_ to specify that a basic block 11887is a landing pad --- one where the exception lands, and corresponds to the 11888code found in the ``catch`` portion of a ``try``/``catch`` sequence. It 11889defines values supplied by the :ref:`personality function <personalityfn>` upon 11890re-entry to the function. The ``resultval`` has the type ``resultty``. 11891 11892Arguments: 11893"""""""""" 11894 11895The optional 11896``cleanup`` flag indicates that the landing pad block is a cleanup. 11897 11898A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and 11899contains the global variable representing the "type" that may be caught 11900or filtered respectively. Unlike the ``catch`` clause, the ``filter`` 11901clause takes an array constant as its argument. Use 11902"``[0 x i8**] undef``" for a filter which cannot throw. The 11903'``landingpad``' instruction must contain *at least* one ``clause`` or 11904the ``cleanup`` flag. 11905 11906Semantics: 11907"""""""""" 11908 11909The '``landingpad``' instruction defines the values which are set by the 11910:ref:`personality function <personalityfn>` upon re-entry to the function, and 11911therefore the "result type" of the ``landingpad`` instruction. As with 11912calling conventions, how the personality function results are 11913represented in LLVM IR is target specific. 11914 11915The clauses are applied in order from top to bottom. If two 11916``landingpad`` instructions are merged together through inlining, the 11917clauses from the calling function are appended to the list of clauses. 11918When the call stack is being unwound due to an exception being thrown, 11919the exception is compared against each ``clause`` in turn. If it doesn't 11920match any of the clauses, and the ``cleanup`` flag is not set, then 11921unwinding continues further up the call stack. 11922 11923The ``landingpad`` instruction has several restrictions: 11924 11925- A landing pad block is a basic block which is the unwind destination 11926 of an '``invoke``' instruction. 11927- A landing pad block must have a '``landingpad``' instruction as its 11928 first non-PHI instruction. 11929- There can be only one '``landingpad``' instruction within the landing 11930 pad block. 11931- A basic block that is not a landing pad block may not include a 11932 '``landingpad``' instruction. 11933 11934Example: 11935"""""""" 11936 11937.. code-block:: llvm 11938 11939 ;; A landing pad which can catch an integer. 11940 %res = landingpad { i8*, i32 } 11941 catch i8** @_ZTIi 11942 ;; A landing pad that is a cleanup. 11943 %res = landingpad { i8*, i32 } 11944 cleanup 11945 ;; A landing pad which can catch an integer and can only throw a double. 11946 %res = landingpad { i8*, i32 } 11947 catch i8** @_ZTIi 11948 filter [1 x i8**] [i8** @_ZTId] 11949 11950.. _i_catchpad: 11951 11952'``catchpad``' Instruction 11953^^^^^^^^^^^^^^^^^^^^^^^^^^ 11954 11955Syntax: 11956""""""" 11957 11958:: 11959 11960 <resultval> = catchpad within <catchswitch> [<args>*] 11961 11962Overview: 11963""""""""" 11964 11965The '``catchpad``' instruction is used by `LLVM's exception handling 11966system <ExceptionHandling.html#overview>`_ to specify that a basic block 11967begins a catch handler --- one where a personality routine attempts to transfer 11968control to catch an exception. 11969 11970Arguments: 11971"""""""""" 11972 11973The ``catchswitch`` operand must always be a token produced by a 11974:ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This 11975ensures that each ``catchpad`` has exactly one predecessor block, and it always 11976terminates in a ``catchswitch``. 11977 11978The ``args`` correspond to whatever information the personality routine 11979requires to know if this is an appropriate handler for the exception. Control 11980will transfer to the ``catchpad`` if this is the first appropriate handler for 11981the exception. 11982 11983The ``resultval`` has the type :ref:`token <t_token>` and is used to match the 11984``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH 11985pads. 11986 11987Semantics: 11988"""""""""" 11989 11990When the call stack is being unwound due to an exception being thrown, the 11991exception is compared against the ``args``. If it doesn't match, control will 11992not reach the ``catchpad`` instruction. The representation of ``args`` is 11993entirely target and personality function-specific. 11994 11995Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad`` 11996instruction must be the first non-phi of its parent basic block. 11997 11998The meaning of the tokens produced and consumed by ``catchpad`` and other "pad" 11999instructions is described in the 12000`Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_. 12001 12002When a ``catchpad`` has been "entered" but not yet "exited" (as 12003described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 12004it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 12005that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 12006 12007Example: 12008"""""""" 12009 12010.. code-block:: text 12011 12012 dispatch: 12013 %cs = catchswitch within none [label %handler0] unwind to caller 12014 ;; A catch block which can catch an integer. 12015 handler0: 12016 %tok = catchpad within %cs [i8** @_ZTIi] 12017 12018.. _i_cleanuppad: 12019 12020'``cleanuppad``' Instruction 12021^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12022 12023Syntax: 12024""""""" 12025 12026:: 12027 12028 <resultval> = cleanuppad within <parent> [<args>*] 12029 12030Overview: 12031""""""""" 12032 12033The '``cleanuppad``' instruction is used by `LLVM's exception handling 12034system <ExceptionHandling.html#overview>`_ to specify that a basic block 12035is a cleanup block --- one where a personality routine attempts to 12036transfer control to run cleanup actions. 12037The ``args`` correspond to whatever additional 12038information the :ref:`personality function <personalityfn>` requires to 12039execute the cleanup. 12040The ``resultval`` has the type :ref:`token <t_token>` and is used to 12041match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`. 12042The ``parent`` argument is the token of the funclet that contains the 12043``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet, 12044this operand may be the token ``none``. 12045 12046Arguments: 12047"""""""""" 12048 12049The instruction takes a list of arbitrary values which are interpreted 12050by the :ref:`personality function <personalityfn>`. 12051 12052Semantics: 12053"""""""""" 12054 12055When the call stack is being unwound due to an exception being thrown, 12056the :ref:`personality function <personalityfn>` transfers control to the 12057``cleanuppad`` with the aid of the personality-specific arguments. 12058As with calling conventions, how the personality function results are 12059represented in LLVM IR is target specific. 12060 12061The ``cleanuppad`` instruction has several restrictions: 12062 12063- A cleanup block is a basic block which is the unwind destination of 12064 an exceptional instruction. 12065- A cleanup block must have a '``cleanuppad``' instruction as its 12066 first non-PHI instruction. 12067- There can be only one '``cleanuppad``' instruction within the 12068 cleanup block. 12069- A basic block that is not a cleanup block may not include a 12070 '``cleanuppad``' instruction. 12071 12072When a ``cleanuppad`` has been "entered" but not yet "exited" (as 12073described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 12074it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 12075that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 12076 12077Example: 12078"""""""" 12079 12080.. code-block:: text 12081 12082 %tok = cleanuppad within %cs [] 12083 12084.. _intrinsics: 12085 12086Intrinsic Functions 12087=================== 12088 12089LLVM supports the notion of an "intrinsic function". These functions 12090have well known names and semantics and are required to follow certain 12091restrictions. Overall, these intrinsics represent an extension mechanism 12092for the LLVM language that does not require changing all of the 12093transformations in LLVM when adding to the language (or the bitcode 12094reader/writer, the parser, etc...). 12095 12096Intrinsic function names must all start with an "``llvm.``" prefix. This 12097prefix is reserved in LLVM for intrinsic names; thus, function names may 12098not begin with this prefix. Intrinsic functions must always be external 12099functions: you cannot define the body of intrinsic functions. Intrinsic 12100functions may only be used in call or invoke instructions: it is illegal 12101to take the address of an intrinsic function. Additionally, because 12102intrinsic functions are part of the LLVM language, it is required if any 12103are added that they be documented here. 12104 12105Some intrinsic functions can be overloaded, i.e., the intrinsic 12106represents a family of functions that perform the same operation but on 12107different data types. Because LLVM can represent over 8 million 12108different integer types, overloading is used commonly to allow an 12109intrinsic function to operate on any integer type. One or more of the 12110argument types or the result type can be overloaded to accept any 12111integer type. Argument types may also be defined as exactly matching a 12112previous argument's type or the result type. This allows an intrinsic 12113function which accepts multiple arguments, but needs all of them to be 12114of the same type, to only be overloaded with respect to a single 12115argument or the result. 12116 12117Overloaded intrinsics will have the names of its overloaded argument 12118types encoded into its function name, each preceded by a period. Only 12119those types which are overloaded result in a name suffix. Arguments 12120whose type is matched against another type do not. For example, the 12121``llvm.ctpop`` function can take an integer of any width and returns an 12122integer of exactly the same integer width. This leads to a family of 12123functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and 12124``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is 12125overloaded, and only one type suffix is required. Because the argument's 12126type is matched against the return type, it does not require its own 12127name suffix. 12128 12129:ref:`Unnamed types <t_opaque>` are encoded as ``s_s``. Overloaded intrinsics 12130that depend on an unnamed type in one of its overloaded argument types get an 12131additional ``.<number>`` suffix. This allows differentiating intrinsics with 12132different unnamed types as arguments. (For example: 12133``llvm.ssa.copy.p0s_s.2(%42*)``) The number is tracked in the LLVM module and 12134it ensures unique names in the module. While linking together two modules, it is 12135still possible to get a name clash. In that case one of the names will be 12136changed by getting a new number. 12137 12138For target developers who are defining intrinsics for back-end code 12139generation, any intrinsic overloads based solely the distinction between 12140integer or floating point types should not be relied upon for correct 12141code generation. In such cases, the recommended approach for target 12142maintainers when defining intrinsics is to create separate integer and 12143FP intrinsics rather than rely on overloading. For example, if different 12144codegen is required for ``llvm.target.foo(<4 x i32>)`` and 12145``llvm.target.foo(<4 x float>)`` then these should be split into 12146different intrinsics. 12147 12148To learn how to add an intrinsic function, please see the `Extending 12149LLVM Guide <ExtendingLLVM.html>`_. 12150 12151.. _int_varargs: 12152 12153Variable Argument Handling Intrinsics 12154------------------------------------- 12155 12156Variable argument support is defined in LLVM with the 12157:ref:`va_arg <i_va_arg>` instruction and these three intrinsic 12158functions. These functions are related to the similarly named macros 12159defined in the ``<stdarg.h>`` header file. 12160 12161All of these functions operate on arguments that use a target-specific 12162value type "``va_list``". The LLVM assembly language reference manual 12163does not define what this type is, so all transformations should be 12164prepared to handle these functions regardless of the type used. 12165 12166This example shows how the :ref:`va_arg <i_va_arg>` instruction and the 12167variable argument handling intrinsic functions are used. 12168 12169.. code-block:: llvm 12170 12171 ; This struct is different for every platform. For most platforms, 12172 ; it is merely an i8*. 12173 %struct.va_list = type { i8* } 12174 12175 ; For Unix x86_64 platforms, va_list is the following struct: 12176 ; %struct.va_list = type { i32, i32, i8*, i8* } 12177 12178 define i32 @test(i32 %X, ...) { 12179 ; Initialize variable argument processing 12180 %ap = alloca %struct.va_list 12181 %ap2 = bitcast %struct.va_list* %ap to i8* 12182 call void @llvm.va_start(i8* %ap2) 12183 12184 ; Read a single integer argument 12185 %tmp = va_arg i8* %ap2, i32 12186 12187 ; Demonstrate usage of llvm.va_copy and llvm.va_end 12188 %aq = alloca i8* 12189 %aq2 = bitcast i8** %aq to i8* 12190 call void @llvm.va_copy(i8* %aq2, i8* %ap2) 12191 call void @llvm.va_end(i8* %aq2) 12192 12193 ; Stop processing of arguments. 12194 call void @llvm.va_end(i8* %ap2) 12195 ret i32 %tmp 12196 } 12197 12198 declare void @llvm.va_start(i8*) 12199 declare void @llvm.va_copy(i8*, i8*) 12200 declare void @llvm.va_end(i8*) 12201 12202.. _int_va_start: 12203 12204'``llvm.va_start``' Intrinsic 12205^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12206 12207Syntax: 12208""""""" 12209 12210:: 12211 12212 declare void @llvm.va_start(i8* <arglist>) 12213 12214Overview: 12215""""""""" 12216 12217The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for 12218subsequent use by ``va_arg``. 12219 12220Arguments: 12221"""""""""" 12222 12223The argument is a pointer to a ``va_list`` element to initialize. 12224 12225Semantics: 12226"""""""""" 12227 12228The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro 12229available in C. In a target-dependent way, it initializes the 12230``va_list`` element to which the argument points, so that the next call 12231to ``va_arg`` will produce the first variable argument passed to the 12232function. Unlike the C ``va_start`` macro, this intrinsic does not need 12233to know the last argument of the function as the compiler can figure 12234that out. 12235 12236'``llvm.va_end``' Intrinsic 12237^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12238 12239Syntax: 12240""""""" 12241 12242:: 12243 12244 declare void @llvm.va_end(i8* <arglist>) 12245 12246Overview: 12247""""""""" 12248 12249The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been 12250initialized previously with ``llvm.va_start`` or ``llvm.va_copy``. 12251 12252Arguments: 12253"""""""""" 12254 12255The argument is a pointer to a ``va_list`` to destroy. 12256 12257Semantics: 12258"""""""""" 12259 12260The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro 12261available in C. In a target-dependent way, it destroys the ``va_list`` 12262element to which the argument points. Calls to 12263:ref:`llvm.va_start <int_va_start>` and 12264:ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to 12265``llvm.va_end``. 12266 12267.. _int_va_copy: 12268 12269'``llvm.va_copy``' Intrinsic 12270^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12271 12272Syntax: 12273""""""" 12274 12275:: 12276 12277 declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>) 12278 12279Overview: 12280""""""""" 12281 12282The '``llvm.va_copy``' intrinsic copies the current argument position 12283from the source argument list to the destination argument list. 12284 12285Arguments: 12286"""""""""" 12287 12288The first argument is a pointer to a ``va_list`` element to initialize. 12289The second argument is a pointer to a ``va_list`` element to copy from. 12290 12291Semantics: 12292"""""""""" 12293 12294The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro 12295available in C. In a target-dependent way, it copies the source 12296``va_list`` element into the destination ``va_list`` element. This 12297intrinsic is necessary because the `` llvm.va_start`` intrinsic may be 12298arbitrarily complex and require, for example, memory allocation. 12299 12300Accurate Garbage Collection Intrinsics 12301-------------------------------------- 12302 12303LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_ 12304(GC) requires the frontend to generate code containing appropriate intrinsic 12305calls and select an appropriate GC strategy which knows how to lower these 12306intrinsics in a manner which is appropriate for the target collector. 12307 12308These intrinsics allow identification of :ref:`GC roots on the 12309stack <int_gcroot>`, as well as garbage collector implementations that 12310require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. 12311Frontends for type-safe garbage collected languages should generate 12312these intrinsics to make use of the LLVM garbage collectors. For more 12313details, see `Garbage Collection with LLVM <GarbageCollection.html>`_. 12314 12315LLVM provides an second experimental set of intrinsics for describing garbage 12316collection safepoints in compiled code. These intrinsics are an alternative 12317to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for 12318:ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The 12319differences in approach are covered in the `Garbage Collection with LLVM 12320<GarbageCollection.html>`_ documentation. The intrinsics themselves are 12321described in :doc:`Statepoints`. 12322 12323.. _int_gcroot: 12324 12325'``llvm.gcroot``' Intrinsic 12326^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12327 12328Syntax: 12329""""""" 12330 12331:: 12332 12333 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata) 12334 12335Overview: 12336""""""""" 12337 12338The '``llvm.gcroot``' intrinsic declares the existence of a GC root to 12339the code generator, and allows some metadata to be associated with it. 12340 12341Arguments: 12342"""""""""" 12343 12344The first argument specifies the address of a stack object that contains 12345the root pointer. The second pointer (which must be either a constant or 12346a global value address) contains the meta-data to be associated with the 12347root. 12348 12349Semantics: 12350"""""""""" 12351 12352At runtime, a call to this intrinsic stores a null pointer into the 12353"ptrloc" location. At compile-time, the code generator generates 12354information to allow the runtime to find the pointer at GC safe points. 12355The '``llvm.gcroot``' intrinsic may only be used in a function which 12356:ref:`specifies a GC algorithm <gc>`. 12357 12358.. _int_gcread: 12359 12360'``llvm.gcread``' Intrinsic 12361^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12362 12363Syntax: 12364""""""" 12365 12366:: 12367 12368 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr) 12369 12370Overview: 12371""""""""" 12372 12373The '``llvm.gcread``' intrinsic identifies reads of references from heap 12374locations, allowing garbage collector implementations that require read 12375barriers. 12376 12377Arguments: 12378"""""""""" 12379 12380The second argument is the address to read from, which should be an 12381address allocated from the garbage collector. The first object is a 12382pointer to the start of the referenced object, if needed by the language 12383runtime (otherwise null). 12384 12385Semantics: 12386"""""""""" 12387 12388The '``llvm.gcread``' intrinsic has the same semantics as a load 12389instruction, but may be replaced with substantially more complex code by 12390the garbage collector runtime, as needed. The '``llvm.gcread``' 12391intrinsic may only be used in a function which :ref:`specifies a GC 12392algorithm <gc>`. 12393 12394.. _int_gcwrite: 12395 12396'``llvm.gcwrite``' Intrinsic 12397^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12398 12399Syntax: 12400""""""" 12401 12402:: 12403 12404 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2) 12405 12406Overview: 12407""""""""" 12408 12409The '``llvm.gcwrite``' intrinsic identifies writes of references to heap 12410locations, allowing garbage collector implementations that require write 12411barriers (such as generational or reference counting collectors). 12412 12413Arguments: 12414"""""""""" 12415 12416The first argument is the reference to store, the second is the start of 12417the object to store it to, and the third is the address of the field of 12418Obj to store to. If the runtime does not require a pointer to the 12419object, Obj may be null. 12420 12421Semantics: 12422"""""""""" 12423 12424The '``llvm.gcwrite``' intrinsic has the same semantics as a store 12425instruction, but may be replaced with substantially more complex code by 12426the garbage collector runtime, as needed. The '``llvm.gcwrite``' 12427intrinsic may only be used in a function which :ref:`specifies a GC 12428algorithm <gc>`. 12429 12430 12431.. _gc_statepoint: 12432 12433'llvm.experimental.gc.statepoint' Intrinsic 12434^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12435 12436Syntax: 12437""""""" 12438 12439:: 12440 12441 declare token 12442 @llvm.experimental.gc.statepoint(i64 <id>, i32 <num patch bytes>, 12443 func_type* elementtype(func_type) <target>, 12444 i64 <#call args>, i64 <flags>, 12445 ... (call parameters), 12446 i64 0, i64 0) 12447 12448Overview: 12449""""""""" 12450 12451The statepoint intrinsic represents a call which is parse-able by the 12452runtime. 12453 12454Operands: 12455""""""""" 12456 12457The 'id' operand is a constant integer that is reported as the ID 12458field in the generated stackmap. LLVM does not interpret this 12459parameter in any way and its meaning is up to the statepoint user to 12460decide. Note that LLVM is free to duplicate code containing 12461statepoint calls, and this may transform IR that had a unique 'id' per 12462lexical call to statepoint to IR that does not. 12463 12464If 'num patch bytes' is non-zero then the call instruction 12465corresponding to the statepoint is not emitted and LLVM emits 'num 12466patch bytes' bytes of nops in its place. LLVM will emit code to 12467prepare the function arguments and retrieve the function return value 12468in accordance to the calling convention; the former before the nop 12469sequence and the latter after the nop sequence. It is expected that 12470the user will patch over the 'num patch bytes' bytes of nops with a 12471calling sequence specific to their runtime before executing the 12472generated machine code. There are no guarantees with respect to the 12473alignment of the nop sequence. Unlike :doc:`StackMaps` statepoints do 12474not have a concept of shadow bytes. Note that semantically the 12475statepoint still represents a call or invoke to 'target', and the nop 12476sequence after patching is expected to represent an operation 12477equivalent to a call or invoke to 'target'. 12478 12479The 'target' operand is the function actually being called. The operand 12480must have an :ref:`elementtype <attr_elementtype>` attribute specifying 12481the function type of the target. The target can be specified as either 12482a symbolic LLVM function, or as an arbitrary Value of pointer type. Note 12483that the function type must match the signature of the callee and the 12484types of the 'call parameters' arguments. 12485 12486The '#call args' operand is the number of arguments to the actual 12487call. It must exactly match the number of arguments passed in the 12488'call parameters' variable length section. 12489 12490The 'flags' operand is used to specify extra information about the 12491statepoint. This is currently only used to mark certain statepoints 12492as GC transitions. This operand is a 64-bit integer with the following 12493layout, where bit 0 is the least significant bit: 12494 12495 +-------+---------------------------------------------------+ 12496 | Bit # | Usage | 12497 +=======+===================================================+ 12498 | 0 | Set if the statepoint is a GC transition, cleared | 12499 | | otherwise. | 12500 +-------+---------------------------------------------------+ 12501 | 1-63 | Reserved for future use; must be cleared. | 12502 +-------+---------------------------------------------------+ 12503 12504The 'call parameters' arguments are simply the arguments which need to 12505be passed to the call target. They will be lowered according to the 12506specified calling convention and otherwise handled like a normal call 12507instruction. The number of arguments must exactly match what is 12508specified in '# call args'. The types must match the signature of 12509'target'. 12510 12511The 'call parameter' attributes must be followed by two 'i64 0' constants. 12512These were originally the length prefixes for 'gc transition parameter' and 12513'deopt parameter' arguments, but the role of these parameter sets have been 12514entirely replaced with the corresponding operand bundles. In a future 12515revision, these now redundant arguments will be removed. 12516 12517Semantics: 12518"""""""""" 12519 12520A statepoint is assumed to read and write all memory. As a result, 12521memory operations can not be reordered past a statepoint. It is 12522illegal to mark a statepoint as being either 'readonly' or 'readnone'. 12523 12524Note that legal IR can not perform any memory operation on a 'gc 12525pointer' argument of the statepoint in a location statically reachable 12526from the statepoint. Instead, the explicitly relocated value (from a 12527``gc.relocate``) must be used. 12528 12529'llvm.experimental.gc.result' Intrinsic 12530^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12531 12532Syntax: 12533""""""" 12534 12535:: 12536 12537 declare type* 12538 @llvm.experimental.gc.result(token %statepoint_token) 12539 12540Overview: 12541""""""""" 12542 12543``gc.result`` extracts the result of the original call instruction 12544which was replaced by the ``gc.statepoint``. The ``gc.result`` 12545intrinsic is actually a family of three intrinsics due to an 12546implementation limitation. Other than the type of the return value, 12547the semantics are the same. 12548 12549Operands: 12550""""""""" 12551 12552The first and only argument is the ``gc.statepoint`` which starts 12553the safepoint sequence of which this ``gc.result`` is a part. 12554Despite the typing of this as a generic token, *only* the value defined 12555by a ``gc.statepoint`` is legal here. 12556 12557Semantics: 12558"""""""""" 12559 12560The ``gc.result`` represents the return value of the call target of 12561the ``statepoint``. The type of the ``gc.result`` must exactly match 12562the type of the target. If the call target returns void, there will 12563be no ``gc.result``. 12564 12565A ``gc.result`` is modeled as a 'readnone' pure function. It has no 12566side effects since it is just a projection of the return value of the 12567previous call represented by the ``gc.statepoint``. 12568 12569'llvm.experimental.gc.relocate' Intrinsic 12570^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12571 12572Syntax: 12573""""""" 12574 12575:: 12576 12577 declare <pointer type> 12578 @llvm.experimental.gc.relocate(token %statepoint_token, 12579 i32 %base_offset, 12580 i32 %pointer_offset) 12581 12582Overview: 12583""""""""" 12584 12585A ``gc.relocate`` returns the potentially relocated value of a pointer 12586at the safepoint. 12587 12588Operands: 12589""""""""" 12590 12591The first argument is the ``gc.statepoint`` which starts the 12592safepoint sequence of which this ``gc.relocation`` is a part. 12593Despite the typing of this as a generic token, *only* the value defined 12594by a ``gc.statepoint`` is legal here. 12595 12596The second and third arguments are both indices into operands of the 12597corresponding statepoint's :ref:`gc-live <ob_gc_live>` operand bundle. 12598 12599The second argument is an index which specifies the allocation for the pointer 12600being relocated. The associated value must be within the object with which the 12601pointer being relocated is associated. The optimizer is free to change *which* 12602interior derived pointer is reported, provided that it does not replace an 12603actual base pointer with another interior derived pointer. Collectors are 12604allowed to rely on the base pointer operand remaining an actual base pointer if 12605so constructed. 12606 12607The third argument is an index which specify the (potentially) derived pointer 12608being relocated. It is legal for this index to be the same as the second 12609argument if-and-only-if a base pointer is being relocated. 12610 12611Semantics: 12612"""""""""" 12613 12614The return value of ``gc.relocate`` is the potentially relocated value 12615of the pointer specified by its arguments. It is unspecified how the 12616value of the returned pointer relates to the argument to the 12617``gc.statepoint`` other than that a) it points to the same source 12618language object with the same offset, and b) the 'based-on' 12619relationship of the newly relocated pointers is a projection of the 12620unrelocated pointers. In particular, the integer value of the pointer 12621returned is unspecified. 12622 12623A ``gc.relocate`` is modeled as a ``readnone`` pure function. It has no 12624side effects since it is just a way to extract information about work 12625done during the actual call modeled by the ``gc.statepoint``. 12626 12627.. _gc.get.pointer.base: 12628 12629'llvm.experimental.gc.get.pointer.base' Intrinsic 12630^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12631 12632Syntax: 12633""""""" 12634 12635:: 12636 12637 declare <pointer type> 12638 @llvm.experimental.gc.get.pointer.base( 12639 <pointer type> readnone nocapture %derived_ptr) 12640 nounwind readnone willreturn 12641 12642Overview: 12643""""""""" 12644 12645``gc.get.pointer.base`` for a derived pointer returns its base pointer. 12646 12647Operands: 12648""""""""" 12649 12650The only argument is a pointer which is based on some object with 12651an unknown offset from the base of said object. 12652 12653Semantics: 12654"""""""""" 12655 12656This intrinsic is used in the abstract machine model for GC to represent 12657the base pointer for an arbitrary derived pointer. 12658 12659This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by 12660replacing all uses of this callsite with the offset of a derived pointer from 12661its base pointer value. The replacement is done as part of the lowering to the 12662explicit statepoint model. 12663 12664The return pointer type must be the same as the type of the parameter. 12665 12666 12667'llvm.experimental.gc.get.pointer.offset' Intrinsic 12668^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12669 12670Syntax: 12671""""""" 12672 12673:: 12674 12675 declare i64 12676 @llvm.experimental.gc.get.pointer.offset( 12677 <pointer type> readnone nocapture %derived_ptr) 12678 nounwind readnone willreturn 12679 12680Overview: 12681""""""""" 12682 12683``gc.get.pointer.offset`` for a derived pointer returns the offset from its 12684base pointer. 12685 12686Operands: 12687""""""""" 12688 12689The only argument is a pointer which is based on some object with 12690an unknown offset from the base of said object. 12691 12692Semantics: 12693"""""""""" 12694 12695This intrinsic is used in the abstract machine model for GC to represent 12696the offset of an arbitrary derived pointer from its base pointer. 12697 12698This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by 12699replacing all uses of this callsite with the offset of a derived pointer from 12700its base pointer value. The replacement is done as part of the lowering to the 12701explicit statepoint model. 12702 12703Basically this call calculates difference between the derived pointer and its 12704base pointer (see :ref:`gc.get.pointer.base`) both ptrtoint casted. But 12705this cast done outside the :ref:`RewriteStatepointsForGC` pass could result 12706in the pointers lost for further lowering from the abstract model to the 12707explicit physical one. 12708 12709Code Generator Intrinsics 12710------------------------- 12711 12712These intrinsics are provided by LLVM to expose special features that 12713may only be implemented with code generator support. 12714 12715'``llvm.returnaddress``' Intrinsic 12716^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12717 12718Syntax: 12719""""""" 12720 12721:: 12722 12723 declare i8* @llvm.returnaddress(i32 <level>) 12724 12725Overview: 12726""""""""" 12727 12728The '``llvm.returnaddress``' intrinsic attempts to compute a 12729target-specific value indicating the return address of the current 12730function or one of its callers. 12731 12732Arguments: 12733"""""""""" 12734 12735The argument to this intrinsic indicates which function to return the 12736address for. Zero indicates the calling function, one indicates its 12737caller, etc. The argument is **required** to be a constant integer 12738value. 12739 12740Semantics: 12741"""""""""" 12742 12743The '``llvm.returnaddress``' intrinsic either returns a pointer 12744indicating the return address of the specified call frame, or zero if it 12745cannot be identified. The value returned by this intrinsic is likely to 12746be incorrect or 0 for arguments other than zero, so it should only be 12747used for debugging purposes. 12748 12749Note that calling this intrinsic does not prevent function inlining or 12750other aggressive transformations, so the value returned may not be that 12751of the obvious source-language caller. 12752 12753'``llvm.addressofreturnaddress``' Intrinsic 12754^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12755 12756Syntax: 12757""""""" 12758 12759:: 12760 12761 declare i8* @llvm.addressofreturnaddress() 12762 12763Overview: 12764""""""""" 12765 12766The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific 12767pointer to the place in the stack frame where the return address of the 12768current function is stored. 12769 12770Semantics: 12771"""""""""" 12772 12773Note that calling this intrinsic does not prevent function inlining or 12774other aggressive transformations, so the value returned may not be that 12775of the obvious source-language caller. 12776 12777This intrinsic is only implemented for x86 and aarch64. 12778 12779'``llvm.sponentry``' Intrinsic 12780^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12781 12782Syntax: 12783""""""" 12784 12785:: 12786 12787 declare i8* @llvm.sponentry() 12788 12789Overview: 12790""""""""" 12791 12792The '``llvm.sponentry``' intrinsic returns the stack pointer value at 12793the entry of the current function calling this intrinsic. 12794 12795Semantics: 12796"""""""""" 12797 12798Note this intrinsic is only verified on AArch64 and ARM. 12799 12800'``llvm.frameaddress``' Intrinsic 12801^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12802 12803Syntax: 12804""""""" 12805 12806:: 12807 12808 declare i8* @llvm.frameaddress(i32 <level>) 12809 12810Overview: 12811""""""""" 12812 12813The '``llvm.frameaddress``' intrinsic attempts to return the 12814target-specific frame pointer value for the specified stack frame. 12815 12816Arguments: 12817"""""""""" 12818 12819The argument to this intrinsic indicates which function to return the 12820frame pointer for. Zero indicates the calling function, one indicates 12821its caller, etc. The argument is **required** to be a constant integer 12822value. 12823 12824Semantics: 12825"""""""""" 12826 12827The '``llvm.frameaddress``' intrinsic either returns a pointer 12828indicating the frame address of the specified call frame, or zero if it 12829cannot be identified. The value returned by this intrinsic is likely to 12830be incorrect or 0 for arguments other than zero, so it should only be 12831used for debugging purposes. 12832 12833Note that calling this intrinsic does not prevent function inlining or 12834other aggressive transformations, so the value returned may not be that 12835of the obvious source-language caller. 12836 12837'``llvm.swift.async.context.addr``' Intrinsic 12838^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12839 12840Syntax: 12841""""""" 12842 12843:: 12844 12845 declare i8** @llvm.swift.async.context.addr() 12846 12847Overview: 12848""""""""" 12849 12850The '``llvm.swift.async.context.addr``' intrinsic returns a pointer to 12851the part of the extended frame record containing the asynchronous 12852context of a Swift execution. 12853 12854Semantics: 12855"""""""""" 12856 12857If the caller has a ``swiftasync`` parameter, that argument will initially 12858be stored at the returned address. If not, it will be initialized to null. 12859 12860'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics 12861^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12862 12863Syntax: 12864""""""" 12865 12866:: 12867 12868 declare void @llvm.localescape(...) 12869 declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx) 12870 12871Overview: 12872""""""""" 12873 12874The '``llvm.localescape``' intrinsic escapes offsets of a collection of static 12875allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a 12876live frame pointer to recover the address of the allocation. The offset is 12877computed during frame layout of the caller of ``llvm.localescape``. 12878 12879Arguments: 12880"""""""""" 12881 12882All arguments to '``llvm.localescape``' must be pointers to static allocas or 12883casts of static allocas. Each function can only call '``llvm.localescape``' 12884once, and it can only do so from the entry block. 12885 12886The ``func`` argument to '``llvm.localrecover``' must be a constant 12887bitcasted pointer to a function defined in the current module. The code 12888generator cannot determine the frame allocation offset of functions defined in 12889other modules. 12890 12891The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a 12892call frame that is currently live. The return value of '``llvm.localaddress``' 12893is one way to produce such a value, but various runtimes also expose a suitable 12894pointer in platform-specific ways. 12895 12896The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to 12897'``llvm.localescape``' to recover. It is zero-indexed. 12898 12899Semantics: 12900"""""""""" 12901 12902These intrinsics allow a group of functions to share access to a set of local 12903stack allocations of a one parent function. The parent function may call the 12904'``llvm.localescape``' intrinsic once from the function entry block, and the 12905child functions can use '``llvm.localrecover``' to access the escaped allocas. 12906The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where 12907the escaped allocas are allocated, which would break attempts to use 12908'``llvm.localrecover``'. 12909 12910'``llvm.seh.try.begin``' and '``llvm.seh.try.end``' Intrinsics 12911^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12912 12913Syntax: 12914""""""" 12915 12916:: 12917 12918 declare void @llvm.seh.try.begin() 12919 declare void @llvm.seh.try.end() 12920 12921Overview: 12922""""""""" 12923 12924The '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' intrinsics mark 12925the boundary of a _try region for Windows SEH Asynchrous Exception Handling. 12926 12927Semantics: 12928"""""""""" 12929 12930When a C-function is compiled with Windows SEH Asynchrous Exception option, 12931-feh_asynch (aka MSVC -EHa), these two intrinsics are injected to mark _try 12932boundary and to prevent potential exceptions from being moved across boundary. 12933Any set of operations can then be confined to the region by reading their leaf 12934inputs via volatile loads and writing their root outputs via volatile stores. 12935 12936'``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' Intrinsics 12937^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12938 12939Syntax: 12940""""""" 12941 12942:: 12943 12944 declare void @llvm.seh.scope.begin() 12945 declare void @llvm.seh.scope.end() 12946 12947Overview: 12948""""""""" 12949 12950The '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' intrinsics mark 12951the boundary of a CPP object lifetime for Windows SEH Asynchrous Exception 12952Handling (MSVC option -EHa). 12953 12954Semantics: 12955"""""""""" 12956 12957LLVM's ordinary exception-handling representation associates EH cleanups and 12958handlers only with ``invoke``s, which normally correspond only to call sites. To 12959support arbitrary faulting instructions, it must be possible to recover the current 12960EH scope for any instruction. Turning every operation in LLVM that could fault 12961into an ``invoke`` of a new, potentially-throwing intrinsic would require adding a 12962large number of intrinsics, impede optimization of those operations, and make 12963compilation slower by introducing many extra basic blocks. These intrinsics can 12964be used instead to mark the region protected by a cleanup, such as for a local 12965C++ object with a non-trivial destructor. ``llvm.seh.scope.begin`` is used to mark 12966the start of the region; it is always called with ``invoke``, with the unwind block 12967being the desired unwind destination for any potentially-throwing instructions 12968within the region. `llvm.seh.scope.end` is used to mark when the scope ends 12969and the EH cleanup is no longer required (e.g. because the destructor is being 12970called). 12971 12972.. _int_read_register: 12973.. _int_read_volatile_register: 12974.. _int_write_register: 12975 12976'``llvm.read_register``', '``llvm.read_volatile_register``', and '``llvm.write_register``' Intrinsics 12977^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12978 12979Syntax: 12980""""""" 12981 12982:: 12983 12984 declare i32 @llvm.read_register.i32(metadata) 12985 declare i64 @llvm.read_register.i64(metadata) 12986 declare i32 @llvm.read_volatile_register.i32(metadata) 12987 declare i64 @llvm.read_volatile_register.i64(metadata) 12988 declare void @llvm.write_register.i32(metadata, i32 @value) 12989 declare void @llvm.write_register.i64(metadata, i64 @value) 12990 !0 = !{!"sp\00"} 12991 12992Overview: 12993""""""""" 12994 12995The '``llvm.read_register``', '``llvm.read_volatile_register``', and 12996'``llvm.write_register``' intrinsics provide access to the named register. 12997The register must be valid on the architecture being compiled to. The type 12998needs to be compatible with the register being read. 12999 13000Semantics: 13001"""""""""" 13002 13003The '``llvm.read_register``' and '``llvm.read_volatile_register``' intrinsics 13004return the current value of the register, where possible. The 13005'``llvm.write_register``' intrinsic sets the current value of the register, 13006where possible. 13007 13008A call to '``llvm.read_volatile_register``' is assumed to have side-effects 13009and possibly return a different value each time (e.g. for a timer register). 13010 13011This is useful to implement named register global variables that need 13012to always be mapped to a specific register, as is common practice on 13013bare-metal programs including OS kernels. 13014 13015The compiler doesn't check for register availability or use of the used 13016register in surrounding code, including inline assembly. Because of that, 13017allocatable registers are not supported. 13018 13019Warning: So far it only works with the stack pointer on selected 13020architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of 13021work is needed to support other registers and even more so, allocatable 13022registers. 13023 13024.. _int_stacksave: 13025 13026'``llvm.stacksave``' Intrinsic 13027^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13028 13029Syntax: 13030""""""" 13031 13032:: 13033 13034 declare i8* @llvm.stacksave() 13035 13036Overview: 13037""""""""" 13038 13039The '``llvm.stacksave``' intrinsic is used to remember the current state 13040of the function stack, for use with 13041:ref:`llvm.stackrestore <int_stackrestore>`. This is useful for 13042implementing language features like scoped automatic variable sized 13043arrays in C99. 13044 13045Semantics: 13046"""""""""" 13047 13048This intrinsic returns an opaque pointer value that can be passed to 13049:ref:`llvm.stackrestore <int_stackrestore>`. When an 13050``llvm.stackrestore`` intrinsic is executed with a value saved from 13051``llvm.stacksave``, it effectively restores the state of the stack to 13052the state it was in when the ``llvm.stacksave`` intrinsic executed. In 13053practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that 13054were allocated after the ``llvm.stacksave`` was executed. 13055 13056.. _int_stackrestore: 13057 13058'``llvm.stackrestore``' Intrinsic 13059^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13060 13061Syntax: 13062""""""" 13063 13064:: 13065 13066 declare void @llvm.stackrestore(i8* %ptr) 13067 13068Overview: 13069""""""""" 13070 13071The '``llvm.stackrestore``' intrinsic is used to restore the state of 13072the function stack to the state it was in when the corresponding 13073:ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is 13074useful for implementing language features like scoped automatic variable 13075sized arrays in C99. 13076 13077Semantics: 13078"""""""""" 13079 13080See the description for :ref:`llvm.stacksave <int_stacksave>`. 13081 13082.. _int_get_dynamic_area_offset: 13083 13084'``llvm.get.dynamic.area.offset``' Intrinsic 13085^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13086 13087Syntax: 13088""""""" 13089 13090:: 13091 13092 declare i32 @llvm.get.dynamic.area.offset.i32() 13093 declare i64 @llvm.get.dynamic.area.offset.i64() 13094 13095Overview: 13096""""""""" 13097 13098 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to 13099 get the offset from native stack pointer to the address of the most 13100 recent dynamic alloca on the caller's stack. These intrinsics are 13101 intended for use in combination with 13102 :ref:`llvm.stacksave <int_stacksave>` to get a 13103 pointer to the most recent dynamic alloca. This is useful, for example, 13104 for AddressSanitizer's stack unpoisoning routines. 13105 13106Semantics: 13107"""""""""" 13108 13109 These intrinsics return a non-negative integer value that can be used to 13110 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>` 13111 on the caller's stack. In particular, for targets where stack grows downwards, 13112 adding this offset to the native stack pointer would get the address of the most 13113 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more 13114 complicated, because subtracting this value from stack pointer would get the address 13115 one past the end of the most recent dynamic alloca. 13116 13117 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 13118 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a 13119 compile-time-known constant value. 13120 13121 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 13122 must match the target's default address space's (address space 0) pointer type. 13123 13124'``llvm.prefetch``' Intrinsic 13125^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13126 13127Syntax: 13128""""""" 13129 13130:: 13131 13132 declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>) 13133 13134Overview: 13135""""""""" 13136 13137The '``llvm.prefetch``' intrinsic is a hint to the code generator to 13138insert a prefetch instruction if supported; otherwise, it is a noop. 13139Prefetches have no effect on the behavior of the program but can change 13140its performance characteristics. 13141 13142Arguments: 13143"""""""""" 13144 13145``address`` is the address to be prefetched, ``rw`` is the specifier 13146determining if the fetch should be for a read (0) or write (1), and 13147``locality`` is a temporal locality specifier ranging from (0) - no 13148locality, to (3) - extremely local keep in cache. The ``cache type`` 13149specifies whether the prefetch is performed on the data (1) or 13150instruction (0) cache. The ``rw``, ``locality`` and ``cache type`` 13151arguments must be constant integers. 13152 13153Semantics: 13154"""""""""" 13155 13156This intrinsic does not modify the behavior of the program. In 13157particular, prefetches cannot trap and do not produce a value. On 13158targets that support this intrinsic, the prefetch can provide hints to 13159the processor cache for better performance. 13160 13161'``llvm.pcmarker``' Intrinsic 13162^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13163 13164Syntax: 13165""""""" 13166 13167:: 13168 13169 declare void @llvm.pcmarker(i32 <id>) 13170 13171Overview: 13172""""""""" 13173 13174The '``llvm.pcmarker``' intrinsic is a method to export a Program 13175Counter (PC) in a region of code to simulators and other tools. The 13176method is target specific, but it is expected that the marker will use 13177exported symbols to transmit the PC of the marker. The marker makes no 13178guarantees that it will remain with any specific instruction after 13179optimizations. It is possible that the presence of a marker will inhibit 13180optimizations. The intended use is to be inserted after optimizations to 13181allow correlations of simulation runs. 13182 13183Arguments: 13184"""""""""" 13185 13186``id`` is a numerical id identifying the marker. 13187 13188Semantics: 13189"""""""""" 13190 13191This intrinsic does not modify the behavior of the program. Backends 13192that do not support this intrinsic may ignore it. 13193 13194'``llvm.readcyclecounter``' Intrinsic 13195^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13196 13197Syntax: 13198""""""" 13199 13200:: 13201 13202 declare i64 @llvm.readcyclecounter() 13203 13204Overview: 13205""""""""" 13206 13207The '``llvm.readcyclecounter``' intrinsic provides access to the cycle 13208counter register (or similar low latency, high accuracy clocks) on those 13209targets that support it. On X86, it should map to RDTSC. On Alpha, it 13210should map to RPCC. As the backing counters overflow quickly (on the 13211order of 9 seconds on alpha), this should only be used for small 13212timings. 13213 13214Semantics: 13215"""""""""" 13216 13217When directly supported, reading the cycle counter should not modify any 13218memory. Implementations are allowed to either return an application 13219specific value or a system wide value. On backends without support, this 13220is lowered to a constant 0. 13221 13222Note that runtime support may be conditional on the privilege-level code is 13223running at and the host platform. 13224 13225'``llvm.clear_cache``' Intrinsic 13226^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13227 13228Syntax: 13229""""""" 13230 13231:: 13232 13233 declare void @llvm.clear_cache(i8*, i8*) 13234 13235Overview: 13236""""""""" 13237 13238The '``llvm.clear_cache``' intrinsic ensures visibility of modifications 13239in the specified range to the execution unit of the processor. On 13240targets with non-unified instruction and data cache, the implementation 13241flushes the instruction cache. 13242 13243Semantics: 13244"""""""""" 13245 13246On platforms with coherent instruction and data caches (e.g. x86), this 13247intrinsic is a nop. On platforms with non-coherent instruction and data 13248cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate 13249instructions or a system call, if cache flushing requires special 13250privileges. 13251 13252The default behavior is to emit a call to ``__clear_cache`` from the run 13253time library. 13254 13255This intrinsic does *not* empty the instruction pipeline. Modifications 13256of the current function are outside the scope of the intrinsic. 13257 13258'``llvm.instrprof.increment``' Intrinsic 13259^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13260 13261Syntax: 13262""""""" 13263 13264:: 13265 13266 declare void @llvm.instrprof.increment(i8* <name>, i64 <hash>, 13267 i32 <num-counters>, i32 <index>) 13268 13269Overview: 13270""""""""" 13271 13272The '``llvm.instrprof.increment``' intrinsic can be emitted by a 13273frontend for use with instrumentation based profiling. These will be 13274lowered by the ``-instrprof`` pass to generate execution counts of a 13275program at runtime. 13276 13277Arguments: 13278"""""""""" 13279 13280The first argument is a pointer to a global variable containing the 13281name of the entity being instrumented. This should generally be the 13282(mangled) function name for a set of counters. 13283 13284The second argument is a hash value that can be used by the consumer 13285of the profile data to detect changes to the instrumented source, and 13286the third is the number of counters associated with ``name``. It is an 13287error if ``hash`` or ``num-counters`` differ between two instances of 13288``instrprof.increment`` that refer to the same name. 13289 13290The last argument refers to which of the counters for ``name`` should 13291be incremented. It should be a value between 0 and ``num-counters``. 13292 13293Semantics: 13294"""""""""" 13295 13296This intrinsic represents an increment of a profiling counter. It will 13297cause the ``-instrprof`` pass to generate the appropriate data 13298structures and the code to increment the appropriate value, in a 13299format that can be written out by a compiler runtime and consumed via 13300the ``llvm-profdata`` tool. 13301 13302'``llvm.instrprof.increment.step``' Intrinsic 13303^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13304 13305Syntax: 13306""""""" 13307 13308:: 13309 13310 declare void @llvm.instrprof.increment.step(i8* <name>, i64 <hash>, 13311 i32 <num-counters>, 13312 i32 <index>, i64 <step>) 13313 13314Overview: 13315""""""""" 13316 13317The '``llvm.instrprof.increment.step``' intrinsic is an extension to 13318the '``llvm.instrprof.increment``' intrinsic with an additional fifth 13319argument to specify the step of the increment. 13320 13321Arguments: 13322"""""""""" 13323The first four arguments are the same as '``llvm.instrprof.increment``' 13324intrinsic. 13325 13326The last argument specifies the value of the increment of the counter variable. 13327 13328Semantics: 13329"""""""""" 13330See description of '``llvm.instrprof.increment``' intrinsic. 13331 13332'``llvm.instrprof.cover``' Intrinsic 13333^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13334 13335Syntax: 13336""""""" 13337 13338:: 13339 13340 declare void @llvm.instrprof.cover(i8* <name>, i64 <hash>, 13341 i32 <num-counters>, i32 <index>) 13342 13343Overview: 13344""""""""" 13345 13346The '``llvm.instrprof.cover``' intrinsic is used to implement coverage 13347instrumentation. 13348 13349Arguments: 13350"""""""""" 13351The arguments are the same as the first four arguments of 13352'``llvm.instrprof.increment``'. 13353 13354Semantics: 13355"""""""""" 13356Similar to the '``llvm.instrprof.increment``' intrinsic, but it stores zero to 13357the profiling variable to signify that the function has been covered. We store 13358zero because this is more efficient on some targets. 13359 13360'``llvm.instrprof.value.profile``' Intrinsic 13361^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13362 13363Syntax: 13364""""""" 13365 13366:: 13367 13368 declare void @llvm.instrprof.value.profile(i8* <name>, i64 <hash>, 13369 i64 <value>, i32 <value_kind>, 13370 i32 <index>) 13371 13372Overview: 13373""""""""" 13374 13375The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a 13376frontend for use with instrumentation based profiling. This will be 13377lowered by the ``-instrprof`` pass to find out the target values, 13378instrumented expressions take in a program at runtime. 13379 13380Arguments: 13381"""""""""" 13382 13383The first argument is a pointer to a global variable containing the 13384name of the entity being instrumented. ``name`` should generally be the 13385(mangled) function name for a set of counters. 13386 13387The second argument is a hash value that can be used by the consumer 13388of the profile data to detect changes to the instrumented source. It 13389is an error if ``hash`` differs between two instances of 13390``llvm.instrprof.*`` that refer to the same name. 13391 13392The third argument is the value of the expression being profiled. The profiled 13393expression's value should be representable as an unsigned 64-bit value. The 13394fourth argument represents the kind of value profiling that is being done. The 13395supported value profiling kinds are enumerated through the 13396``InstrProfValueKind`` type declared in the 13397``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the 13398index of the instrumented expression within ``name``. It should be >= 0. 13399 13400Semantics: 13401"""""""""" 13402 13403This intrinsic represents the point where a call to a runtime routine 13404should be inserted for value profiling of target expressions. ``-instrprof`` 13405pass will generate the appropriate data structures and replace the 13406``llvm.instrprof.value.profile`` intrinsic with the call to the profile 13407runtime library with proper arguments. 13408 13409'``llvm.thread.pointer``' Intrinsic 13410^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13411 13412Syntax: 13413""""""" 13414 13415:: 13416 13417 declare i8* @llvm.thread.pointer() 13418 13419Overview: 13420""""""""" 13421 13422The '``llvm.thread.pointer``' intrinsic returns the value of the thread 13423pointer. 13424 13425Semantics: 13426"""""""""" 13427 13428The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area 13429for the current thread. The exact semantics of this value are target 13430specific: it may point to the start of TLS area, to the end, or somewhere 13431in the middle. Depending on the target, this intrinsic may read a register, 13432call a helper function, read from an alternate memory space, or perform 13433other operations necessary to locate the TLS area. Not all targets support 13434this intrinsic. 13435 13436'``llvm.call.preallocated.setup``' Intrinsic 13437^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13438 13439Syntax: 13440""""""" 13441 13442:: 13443 13444 declare token @llvm.call.preallocated.setup(i32 %num_args) 13445 13446Overview: 13447""""""""" 13448 13449The '``llvm.call.preallocated.setup``' intrinsic returns a token which can 13450be used with a call's ``"preallocated"`` operand bundle to indicate that 13451certain arguments are allocated and initialized before the call. 13452 13453Semantics: 13454"""""""""" 13455 13456The '``llvm.call.preallocated.setup``' intrinsic returns a token which is 13457associated with at most one call. The token can be passed to 13458'``@llvm.call.preallocated.arg``' to get a pointer to get that 13459corresponding argument. The token must be the parameter to a 13460``"preallocated"`` operand bundle for the corresponding call. 13461 13462Nested calls to '``llvm.call.preallocated.setup``' are allowed, but must 13463be properly nested. e.g. 13464 13465:: code-block:: llvm 13466 13467 %t1 = call token @llvm.call.preallocated.setup(i32 0) 13468 %t2 = call token @llvm.call.preallocated.setup(i32 0) 13469 call void foo() ["preallocated"(token %t2)] 13470 call void foo() ["preallocated"(token %t1)] 13471 13472is allowed, but not 13473 13474:: code-block:: llvm 13475 13476 %t1 = call token @llvm.call.preallocated.setup(i32 0) 13477 %t2 = call token @llvm.call.preallocated.setup(i32 0) 13478 call void foo() ["preallocated"(token %t1)] 13479 call void foo() ["preallocated"(token %t2)] 13480 13481.. _int_call_preallocated_arg: 13482 13483'``llvm.call.preallocated.arg``' Intrinsic 13484^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13485 13486Syntax: 13487""""""" 13488 13489:: 13490 13491 declare i8* @llvm.call.preallocated.arg(token %setup_token, i32 %arg_index) 13492 13493Overview: 13494""""""""" 13495 13496The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the 13497corresponding preallocated argument for the preallocated call. 13498 13499Semantics: 13500"""""""""" 13501 13502The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the 13503``%arg_index``th argument with the ``preallocated`` attribute for 13504the call associated with the ``%setup_token``, which must be from 13505'``llvm.call.preallocated.setup``'. 13506 13507A call to '``llvm.call.preallocated.arg``' must have a call site 13508``preallocated`` attribute. The type of the ``preallocated`` attribute must 13509match the type used by the ``preallocated`` attribute of the corresponding 13510argument at the preallocated call. The type is used in the case that an 13511``llvm.call.preallocated.setup`` does not have a corresponding call (e.g. due 13512to DCE), where otherwise we cannot know how large the arguments are. 13513 13514It is undefined behavior if this is called with a token from an 13515'``llvm.call.preallocated.setup``' if another 13516'``llvm.call.preallocated.setup``' has already been called or if the 13517preallocated call corresponding to the '``llvm.call.preallocated.setup``' 13518has already been called. 13519 13520.. _int_call_preallocated_teardown: 13521 13522'``llvm.call.preallocated.teardown``' Intrinsic 13523^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13524 13525Syntax: 13526""""""" 13527 13528:: 13529 13530 declare i8* @llvm.call.preallocated.teardown(token %setup_token) 13531 13532Overview: 13533""""""""" 13534 13535The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack 13536created by a '``llvm.call.preallocated.setup``'. 13537 13538Semantics: 13539"""""""""" 13540 13541The token argument must be a '``llvm.call.preallocated.setup``'. 13542 13543The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack 13544allocated by the corresponding '``llvm.call.preallocated.setup``'. Exactly 13545one of this or the preallocated call must be called to prevent stack leaks. 13546It is undefined behavior to call both a '``llvm.call.preallocated.teardown``' 13547and the preallocated call for a given '``llvm.call.preallocated.setup``'. 13548 13549For example, if the stack is allocated for a preallocated call by a 13550'``llvm.call.preallocated.setup``', then an initializer function called on an 13551allocated argument throws an exception, there should be a 13552'``llvm.call.preallocated.teardown``' in the exception handler to prevent 13553stack leaks. 13554 13555Following the nesting rules in '``llvm.call.preallocated.setup``', nested 13556calls to '``llvm.call.preallocated.setup``' and 13557'``llvm.call.preallocated.teardown``' are allowed but must be properly 13558nested. 13559 13560Example: 13561"""""""" 13562 13563.. code-block:: llvm 13564 13565 %cs = call token @llvm.call.preallocated.setup(i32 1) 13566 %x = call i8* @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32) 13567 %y = bitcast i8* %x to i32* 13568 invoke void @constructor(i32* %y) to label %conta unwind label %contb 13569 conta: 13570 call void @foo1(i32* preallocated(i32) %y) ["preallocated"(token %cs)] 13571 ret void 13572 contb: 13573 %s = catchswitch within none [label %catch] unwind to caller 13574 catch: 13575 %p = catchpad within %s [] 13576 call void @llvm.call.preallocated.teardown(token %cs) 13577 ret void 13578 13579Standard C/C++ Library Intrinsics 13580--------------------------------- 13581 13582LLVM provides intrinsics for a few important standard C/C++ library 13583functions. These intrinsics allow source-language front-ends to pass 13584information about the alignment of the pointer arguments to the code 13585generator, providing opportunity for more efficient code generation. 13586 13587 13588'``llvm.abs.*``' Intrinsic 13589^^^^^^^^^^^^^^^^^^^^^^^^^^ 13590 13591Syntax: 13592""""""" 13593 13594This is an overloaded intrinsic. You can use ``llvm.abs`` on any 13595integer bit width or any vector of integer elements. 13596 13597:: 13598 13599 declare i32 @llvm.abs.i32(i32 <src>, i1 <is_int_min_poison>) 13600 declare <4 x i32> @llvm.abs.v4i32(<4 x i32> <src>, i1 <is_int_min_poison>) 13601 13602Overview: 13603""""""""" 13604 13605The '``llvm.abs``' family of intrinsic functions returns the absolute value 13606of an argument. 13607 13608Arguments: 13609"""""""""" 13610 13611The first argument is the value for which the absolute value is to be returned. 13612This argument may be of any integer type or a vector with integer element type. 13613The return type must match the first argument type. 13614 13615The second argument must be a constant and is a flag to indicate whether the 13616result value of the '``llvm.abs``' intrinsic is a 13617:ref:`poison value <poisonvalues>` if the argument is statically or dynamically 13618an ``INT_MIN`` value. 13619 13620Semantics: 13621"""""""""" 13622 13623The '``llvm.abs``' intrinsic returns the magnitude (always positive) of the 13624argument or each element of a vector argument.". If the argument is ``INT_MIN``, 13625then the result is also ``INT_MIN`` if ``is_int_min_poison == 0`` and 13626``poison`` otherwise. 13627 13628 13629'``llvm.smax.*``' Intrinsic 13630^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13631 13632Syntax: 13633""""""" 13634 13635This is an overloaded intrinsic. You can use ``@llvm.smax`` on any 13636integer bit width or any vector of integer elements. 13637 13638:: 13639 13640 declare i32 @llvm.smax.i32(i32 %a, i32 %b) 13641 declare <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b) 13642 13643Overview: 13644""""""""" 13645 13646Return the larger of ``%a`` and ``%b`` comparing the values as signed integers. 13647Vector intrinsics operate on a per-element basis. The larger element of ``%a`` 13648and ``%b`` at a given index is returned for that index. 13649 13650Arguments: 13651"""""""""" 13652 13653The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13654integer element type. The argument types must match each other, and the return 13655type must match the argument type. 13656 13657 13658'``llvm.smin.*``' Intrinsic 13659^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13660 13661Syntax: 13662""""""" 13663 13664This is an overloaded intrinsic. You can use ``@llvm.smin`` on any 13665integer bit width or any vector of integer elements. 13666 13667:: 13668 13669 declare i32 @llvm.smin.i32(i32 %a, i32 %b) 13670 declare <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b) 13671 13672Overview: 13673""""""""" 13674 13675Return the smaller of ``%a`` and ``%b`` comparing the values as signed integers. 13676Vector intrinsics operate on a per-element basis. The smaller element of ``%a`` 13677and ``%b`` at a given index is returned for that index. 13678 13679Arguments: 13680"""""""""" 13681 13682The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13683integer element type. The argument types must match each other, and the return 13684type must match the argument type. 13685 13686 13687'``llvm.umax.*``' Intrinsic 13688^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13689 13690Syntax: 13691""""""" 13692 13693This is an overloaded intrinsic. You can use ``@llvm.umax`` on any 13694integer bit width or any vector of integer elements. 13695 13696:: 13697 13698 declare i32 @llvm.umax.i32(i32 %a, i32 %b) 13699 declare <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b) 13700 13701Overview: 13702""""""""" 13703 13704Return the larger of ``%a`` and ``%b`` comparing the values as unsigned 13705integers. Vector intrinsics operate on a per-element basis. The larger element 13706of ``%a`` and ``%b`` at a given index is returned for that index. 13707 13708Arguments: 13709"""""""""" 13710 13711The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13712integer element type. The argument types must match each other, and the return 13713type must match the argument type. 13714 13715 13716'``llvm.umin.*``' Intrinsic 13717^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13718 13719Syntax: 13720""""""" 13721 13722This is an overloaded intrinsic. You can use ``@llvm.umin`` on any 13723integer bit width or any vector of integer elements. 13724 13725:: 13726 13727 declare i32 @llvm.umin.i32(i32 %a, i32 %b) 13728 declare <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b) 13729 13730Overview: 13731""""""""" 13732 13733Return the smaller of ``%a`` and ``%b`` comparing the values as unsigned 13734integers. Vector intrinsics operate on a per-element basis. The smaller element 13735of ``%a`` and ``%b`` at a given index is returned for that index. 13736 13737Arguments: 13738"""""""""" 13739 13740The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13741integer element type. The argument types must match each other, and the return 13742type must match the argument type. 13743 13744 13745.. _int_memcpy: 13746 13747'``llvm.memcpy``' Intrinsic 13748^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13749 13750Syntax: 13751""""""" 13752 13753This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any 13754integer bit width and for different address spaces. Not all targets 13755support all bit widths however. 13756 13757:: 13758 13759 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 13760 i32 <len>, i1 <isvolatile>) 13761 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 13762 i64 <len>, i1 <isvolatile>) 13763 13764Overview: 13765""""""""" 13766 13767The '``llvm.memcpy.*``' intrinsics copy a block of memory from the 13768source location to the destination location. 13769 13770Note that, unlike the standard libc function, the ``llvm.memcpy.*`` 13771intrinsics do not return a value, takes extra isvolatile 13772arguments and the pointers can be in specified address spaces. 13773 13774Arguments: 13775"""""""""" 13776 13777The first argument is a pointer to the destination, the second is a 13778pointer to the source. The third argument is an integer argument 13779specifying the number of bytes to copy, and the fourth is a 13780boolean indicating a volatile access. 13781 13782The :ref:`align <attr_align>` parameter attribute can be provided 13783for the first and second arguments. 13784 13785If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is 13786a :ref:`volatile operation <volatile>`. The detailed access behavior is not 13787very cleanly specified and it is unwise to depend on it. 13788 13789Semantics: 13790"""""""""" 13791 13792The '``llvm.memcpy.*``' intrinsics copy a block of memory from the source 13793location to the destination location, which must either be equal or 13794non-overlapping. It copies "len" bytes of memory over. If the argument is known 13795to be aligned to some boundary, this can be specified as an attribute on the 13796argument. 13797 13798If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 13799the arguments. 13800If ``<len>`` is not a well-defined value, the behavior is undefined. 13801If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined, 13802otherwise the behavior is undefined. 13803 13804.. _int_memcpy_inline: 13805 13806'``llvm.memcpy.inline``' Intrinsic 13807^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13808 13809Syntax: 13810""""""" 13811 13812This is an overloaded intrinsic. You can use ``llvm.memcpy.inline`` on any 13813integer bit width and for different address spaces. Not all targets 13814support all bit widths however. 13815 13816:: 13817 13818 declare void @llvm.memcpy.inline.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 13819 i32 <len>, i1 <isvolatile>) 13820 declare void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 13821 i64 <len>, i1 <isvolatile>) 13822 13823Overview: 13824""""""""" 13825 13826The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the 13827source location to the destination location and guarantees that no external 13828functions are called. 13829 13830Note that, unlike the standard libc function, the ``llvm.memcpy.inline.*`` 13831intrinsics do not return a value, takes extra isvolatile 13832arguments and the pointers can be in specified address spaces. 13833 13834Arguments: 13835"""""""""" 13836 13837The first argument is a pointer to the destination, the second is a 13838pointer to the source. The third argument is a constant integer argument 13839specifying the number of bytes to copy, and the fourth is a 13840boolean indicating a volatile access. 13841 13842The :ref:`align <attr_align>` parameter attribute can be provided 13843for the first and second arguments. 13844 13845If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy.inline`` call is 13846a :ref:`volatile operation <volatile>`. The detailed access behavior is not 13847very cleanly specified and it is unwise to depend on it. 13848 13849Semantics: 13850"""""""""" 13851 13852The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the 13853source location to the destination location, which are not allowed to 13854overlap. It copies "len" bytes of memory over. If the argument is known 13855to be aligned to some boundary, this can be specified as an attribute on 13856the argument. 13857The behavior of '``llvm.memcpy.inline.*``' is equivalent to the behavior of 13858'``llvm.memcpy.*``', but the generated code is guaranteed not to call any 13859external functions. 13860 13861.. _int_memmove: 13862 13863'``llvm.memmove``' Intrinsic 13864^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13865 13866Syntax: 13867""""""" 13868 13869This is an overloaded intrinsic. You can use llvm.memmove on any integer 13870bit width and for different address space. Not all targets support all 13871bit widths however. 13872 13873:: 13874 13875 declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 13876 i32 <len>, i1 <isvolatile>) 13877 declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 13878 i64 <len>, i1 <isvolatile>) 13879 13880Overview: 13881""""""""" 13882 13883The '``llvm.memmove.*``' intrinsics move a block of memory from the 13884source location to the destination location. It is similar to the 13885'``llvm.memcpy``' intrinsic but allows the two memory locations to 13886overlap. 13887 13888Note that, unlike the standard libc function, the ``llvm.memmove.*`` 13889intrinsics do not return a value, takes an extra isvolatile 13890argument and the pointers can be in specified address spaces. 13891 13892Arguments: 13893"""""""""" 13894 13895The first argument is a pointer to the destination, the second is a 13896pointer to the source. The third argument is an integer argument 13897specifying the number of bytes to copy, and the fourth is a 13898boolean indicating a volatile access. 13899 13900The :ref:`align <attr_align>` parameter attribute can be provided 13901for the first and second arguments. 13902 13903If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call 13904is a :ref:`volatile operation <volatile>`. The detailed access behavior is 13905not very cleanly specified and it is unwise to depend on it. 13906 13907Semantics: 13908"""""""""" 13909 13910The '``llvm.memmove.*``' intrinsics copy a block of memory from the 13911source location to the destination location, which may overlap. It 13912copies "len" bytes of memory over. If the argument is known to be 13913aligned to some boundary, this can be specified as an attribute on 13914the argument. 13915 13916If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 13917the arguments. 13918If ``<len>`` is not a well-defined value, the behavior is undefined. 13919If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined, 13920otherwise the behavior is undefined. 13921 13922.. _int_memset: 13923 13924'``llvm.memset.*``' Intrinsics 13925^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13926 13927Syntax: 13928""""""" 13929 13930This is an overloaded intrinsic. You can use llvm.memset on any integer 13931bit width and for different address spaces. However, not all targets 13932support all bit widths. 13933 13934:: 13935 13936 declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>, 13937 i32 <len>, i1 <isvolatile>) 13938 declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>, 13939 i64 <len>, i1 <isvolatile>) 13940 13941Overview: 13942""""""""" 13943 13944The '``llvm.memset.*``' intrinsics fill a block of memory with a 13945particular byte value. 13946 13947Note that, unlike the standard libc function, the ``llvm.memset`` 13948intrinsic does not return a value and takes an extra volatile 13949argument. Also, the destination can be in an arbitrary address space. 13950 13951Arguments: 13952"""""""""" 13953 13954The first argument is a pointer to the destination to fill, the second 13955is the byte value with which to fill it, the third argument is an 13956integer argument specifying the number of bytes to fill, and the fourth 13957is a boolean indicating a volatile access. 13958 13959The :ref:`align <attr_align>` parameter attribute can be provided 13960for the first arguments. 13961 13962If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is 13963a :ref:`volatile operation <volatile>`. The detailed access behavior is not 13964very cleanly specified and it is unwise to depend on it. 13965 13966Semantics: 13967"""""""""" 13968 13969The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting 13970at the destination location. If the argument is known to be 13971aligned to some boundary, this can be specified as an attribute on 13972the argument. 13973 13974If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 13975the arguments. 13976If ``<len>`` is not a well-defined value, the behavior is undefined. 13977If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the 13978behavior is undefined. 13979 13980.. _int_memset_inline: 13981 13982'``llvm.memset.inline``' Intrinsic 13983^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13984 13985Syntax: 13986""""""" 13987 13988This is an overloaded intrinsic. You can use ``llvm.memset.inline`` on any 13989integer bit width and for different address spaces. Not all targets 13990support all bit widths however. 13991 13992:: 13993 13994 declare void @llvm.memset.inline.p0i8.p0i8.i32(i8* <dest>, i8 <val>, 13995 i32 <len>, 13996 i1 <isvolatile>) 13997 declare void @llvm.memset.inline.p0i8.p0i8.i64(i8* <dest>, i8 <val>, 13998 i64 <len>, 13999 i1 <isvolatile>) 14000 14001Overview: 14002""""""""" 14003 14004The '``llvm.memset.inline.*``' intrinsics fill a block of memory with a 14005particular byte value and guarantees that no external functions are called. 14006 14007Note that, unlike the standard libc function, the ``llvm.memset.inline.*`` 14008intrinsics do not return a value, take an extra isvolatile argument and the 14009pointer can be in specified address spaces. 14010 14011Arguments: 14012"""""""""" 14013 14014The first argument is a pointer to the destination to fill, the second 14015is the byte value with which to fill it, the third argument is a constant 14016integer argument specifying the number of bytes to fill, and the fourth 14017is a boolean indicating a volatile access. 14018 14019The :ref:`align <attr_align>` parameter attribute can be provided 14020for the first argument. 14021 14022If the ``isvolatile`` parameter is ``true``, the ``llvm.memset.inline`` call is 14023a :ref:`volatile operation <volatile>`. The detailed access behavior is not 14024very cleanly specified and it is unwise to depend on it. 14025 14026Semantics: 14027"""""""""" 14028 14029The '``llvm.memset.inline.*``' intrinsics fill "len" bytes of memory starting 14030at the destination location. If the argument is known to be 14031aligned to some boundary, this can be specified as an attribute on 14032the argument. 14033 14034``len`` must be a constant expression. 14035If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 14036the arguments. 14037If ``<len>`` is not a well-defined value, the behavior is undefined. 14038If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the 14039behavior is undefined. 14040 14041The behavior of '``llvm.memset.inline.*``' is equivalent to the behavior of 14042'``llvm.memset.*``', but the generated code is guaranteed not to call any 14043external functions. 14044 14045'``llvm.sqrt.*``' Intrinsic 14046^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14047 14048Syntax: 14049""""""" 14050 14051This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any 14052floating-point or vector of floating-point type. Not all targets support 14053all types however. 14054 14055:: 14056 14057 declare float @llvm.sqrt.f32(float %Val) 14058 declare double @llvm.sqrt.f64(double %Val) 14059 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val) 14060 declare fp128 @llvm.sqrt.f128(fp128 %Val) 14061 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val) 14062 14063Overview: 14064""""""""" 14065 14066The '``llvm.sqrt``' intrinsics return the square root of the specified value. 14067 14068Arguments: 14069"""""""""" 14070 14071The argument and return value are floating-point numbers of the same type. 14072 14073Semantics: 14074"""""""""" 14075 14076Return the same value as a corresponding libm '``sqrt``' function but without 14077trapping or setting ``errno``. For types specified by IEEE-754, the result 14078matches a conforming libm implementation. 14079 14080When specified with the fast-math-flag 'afn', the result may be approximated 14081using a less accurate calculation. 14082 14083'``llvm.powi.*``' Intrinsic 14084^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14085 14086Syntax: 14087""""""" 14088 14089This is an overloaded intrinsic. You can use ``llvm.powi`` on any 14090floating-point or vector of floating-point type. Not all targets support 14091all types however. 14092 14093Generally, the only supported type for the exponent is the one matching 14094with the C type ``int``. 14095 14096:: 14097 14098 declare float @llvm.powi.f32.i32(float %Val, i32 %power) 14099 declare double @llvm.powi.f64.i16(double %Val, i16 %power) 14100 declare x86_fp80 @llvm.powi.f80.i32(x86_fp80 %Val, i32 %power) 14101 declare fp128 @llvm.powi.f128.i32(fp128 %Val, i32 %power) 14102 declare ppc_fp128 @llvm.powi.ppcf128.i32(ppc_fp128 %Val, i32 %power) 14103 14104Overview: 14105""""""""" 14106 14107The '``llvm.powi.*``' intrinsics return the first operand raised to the 14108specified (positive or negative) power. The order of evaluation of 14109multiplications is not defined. When a vector of floating-point type is 14110used, the second argument remains a scalar integer value. 14111 14112Arguments: 14113"""""""""" 14114 14115The second argument is an integer power, and the first is a value to 14116raise to that power. 14117 14118Semantics: 14119"""""""""" 14120 14121This function returns the first value raised to the second power with an 14122unspecified sequence of rounding operations. 14123 14124'``llvm.sin.*``' Intrinsic 14125^^^^^^^^^^^^^^^^^^^^^^^^^^ 14126 14127Syntax: 14128""""""" 14129 14130This is an overloaded intrinsic. You can use ``llvm.sin`` on any 14131floating-point or vector of floating-point type. Not all targets support 14132all types however. 14133 14134:: 14135 14136 declare float @llvm.sin.f32(float %Val) 14137 declare double @llvm.sin.f64(double %Val) 14138 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val) 14139 declare fp128 @llvm.sin.f128(fp128 %Val) 14140 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val) 14141 14142Overview: 14143""""""""" 14144 14145The '``llvm.sin.*``' intrinsics return the sine of the operand. 14146 14147Arguments: 14148"""""""""" 14149 14150The argument and return value are floating-point numbers of the same type. 14151 14152Semantics: 14153"""""""""" 14154 14155Return the same value as a corresponding libm '``sin``' function but without 14156trapping or setting ``errno``. 14157 14158When specified with the fast-math-flag 'afn', the result may be approximated 14159using a less accurate calculation. 14160 14161'``llvm.cos.*``' Intrinsic 14162^^^^^^^^^^^^^^^^^^^^^^^^^^ 14163 14164Syntax: 14165""""""" 14166 14167This is an overloaded intrinsic. You can use ``llvm.cos`` on any 14168floating-point or vector of floating-point type. Not all targets support 14169all types however. 14170 14171:: 14172 14173 declare float @llvm.cos.f32(float %Val) 14174 declare double @llvm.cos.f64(double %Val) 14175 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val) 14176 declare fp128 @llvm.cos.f128(fp128 %Val) 14177 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val) 14178 14179Overview: 14180""""""""" 14181 14182The '``llvm.cos.*``' intrinsics return the cosine of the operand. 14183 14184Arguments: 14185"""""""""" 14186 14187The argument and return value are floating-point numbers of the same type. 14188 14189Semantics: 14190"""""""""" 14191 14192Return the same value as a corresponding libm '``cos``' function but without 14193trapping or setting ``errno``. 14194 14195When specified with the fast-math-flag 'afn', the result may be approximated 14196using a less accurate calculation. 14197 14198'``llvm.pow.*``' Intrinsic 14199^^^^^^^^^^^^^^^^^^^^^^^^^^ 14200 14201Syntax: 14202""""""" 14203 14204This is an overloaded intrinsic. You can use ``llvm.pow`` on any 14205floating-point or vector of floating-point type. Not all targets support 14206all types however. 14207 14208:: 14209 14210 declare float @llvm.pow.f32(float %Val, float %Power) 14211 declare double @llvm.pow.f64(double %Val, double %Power) 14212 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power) 14213 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power) 14214 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power) 14215 14216Overview: 14217""""""""" 14218 14219The '``llvm.pow.*``' intrinsics return the first operand raised to the 14220specified (positive or negative) power. 14221 14222Arguments: 14223"""""""""" 14224 14225The arguments and return value are floating-point numbers of the same type. 14226 14227Semantics: 14228"""""""""" 14229 14230Return the same value as a corresponding libm '``pow``' function but without 14231trapping or setting ``errno``. 14232 14233When specified with the fast-math-flag 'afn', the result may be approximated 14234using a less accurate calculation. 14235 14236'``llvm.exp.*``' Intrinsic 14237^^^^^^^^^^^^^^^^^^^^^^^^^^ 14238 14239Syntax: 14240""""""" 14241 14242This is an overloaded intrinsic. You can use ``llvm.exp`` on any 14243floating-point or vector of floating-point type. Not all targets support 14244all types however. 14245 14246:: 14247 14248 declare float @llvm.exp.f32(float %Val) 14249 declare double @llvm.exp.f64(double %Val) 14250 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val) 14251 declare fp128 @llvm.exp.f128(fp128 %Val) 14252 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val) 14253 14254Overview: 14255""""""""" 14256 14257The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified 14258value. 14259 14260Arguments: 14261"""""""""" 14262 14263The argument and return value are floating-point numbers of the same type. 14264 14265Semantics: 14266"""""""""" 14267 14268Return the same value as a corresponding libm '``exp``' function but without 14269trapping or setting ``errno``. 14270 14271When specified with the fast-math-flag 'afn', the result may be approximated 14272using a less accurate calculation. 14273 14274'``llvm.exp2.*``' Intrinsic 14275^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14276 14277Syntax: 14278""""""" 14279 14280This is an overloaded intrinsic. You can use ``llvm.exp2`` on any 14281floating-point or vector of floating-point type. Not all targets support 14282all types however. 14283 14284:: 14285 14286 declare float @llvm.exp2.f32(float %Val) 14287 declare double @llvm.exp2.f64(double %Val) 14288 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val) 14289 declare fp128 @llvm.exp2.f128(fp128 %Val) 14290 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val) 14291 14292Overview: 14293""""""""" 14294 14295The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the 14296specified value. 14297 14298Arguments: 14299"""""""""" 14300 14301The argument and return value are floating-point numbers of the same type. 14302 14303Semantics: 14304"""""""""" 14305 14306Return the same value as a corresponding libm '``exp2``' function but without 14307trapping or setting ``errno``. 14308 14309When specified with the fast-math-flag 'afn', the result may be approximated 14310using a less accurate calculation. 14311 14312'``llvm.log.*``' Intrinsic 14313^^^^^^^^^^^^^^^^^^^^^^^^^^ 14314 14315Syntax: 14316""""""" 14317 14318This is an overloaded intrinsic. You can use ``llvm.log`` on any 14319floating-point or vector of floating-point type. Not all targets support 14320all types however. 14321 14322:: 14323 14324 declare float @llvm.log.f32(float %Val) 14325 declare double @llvm.log.f64(double %Val) 14326 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val) 14327 declare fp128 @llvm.log.f128(fp128 %Val) 14328 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val) 14329 14330Overview: 14331""""""""" 14332 14333The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified 14334value. 14335 14336Arguments: 14337"""""""""" 14338 14339The argument and return value are floating-point numbers of the same type. 14340 14341Semantics: 14342"""""""""" 14343 14344Return the same value as a corresponding libm '``log``' function but without 14345trapping or setting ``errno``. 14346 14347When specified with the fast-math-flag 'afn', the result may be approximated 14348using a less accurate calculation. 14349 14350'``llvm.log10.*``' Intrinsic 14351^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14352 14353Syntax: 14354""""""" 14355 14356This is an overloaded intrinsic. You can use ``llvm.log10`` on any 14357floating-point or vector of floating-point type. Not all targets support 14358all types however. 14359 14360:: 14361 14362 declare float @llvm.log10.f32(float %Val) 14363 declare double @llvm.log10.f64(double %Val) 14364 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val) 14365 declare fp128 @llvm.log10.f128(fp128 %Val) 14366 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val) 14367 14368Overview: 14369""""""""" 14370 14371The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the 14372specified value. 14373 14374Arguments: 14375"""""""""" 14376 14377The argument and return value are floating-point numbers of the same type. 14378 14379Semantics: 14380"""""""""" 14381 14382Return the same value as a corresponding libm '``log10``' function but without 14383trapping or setting ``errno``. 14384 14385When specified with the fast-math-flag 'afn', the result may be approximated 14386using a less accurate calculation. 14387 14388'``llvm.log2.*``' Intrinsic 14389^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14390 14391Syntax: 14392""""""" 14393 14394This is an overloaded intrinsic. You can use ``llvm.log2`` on any 14395floating-point or vector of floating-point type. Not all targets support 14396all types however. 14397 14398:: 14399 14400 declare float @llvm.log2.f32(float %Val) 14401 declare double @llvm.log2.f64(double %Val) 14402 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val) 14403 declare fp128 @llvm.log2.f128(fp128 %Val) 14404 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val) 14405 14406Overview: 14407""""""""" 14408 14409The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified 14410value. 14411 14412Arguments: 14413"""""""""" 14414 14415The argument and return value are floating-point numbers of the same type. 14416 14417Semantics: 14418"""""""""" 14419 14420Return the same value as a corresponding libm '``log2``' function but without 14421trapping or setting ``errno``. 14422 14423When specified with the fast-math-flag 'afn', the result may be approximated 14424using a less accurate calculation. 14425 14426.. _int_fma: 14427 14428'``llvm.fma.*``' Intrinsic 14429^^^^^^^^^^^^^^^^^^^^^^^^^^ 14430 14431Syntax: 14432""""""" 14433 14434This is an overloaded intrinsic. You can use ``llvm.fma`` on any 14435floating-point or vector of floating-point type. Not all targets support 14436all types however. 14437 14438:: 14439 14440 declare float @llvm.fma.f32(float %a, float %b, float %c) 14441 declare double @llvm.fma.f64(double %a, double %b, double %c) 14442 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c) 14443 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c) 14444 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c) 14445 14446Overview: 14447""""""""" 14448 14449The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation. 14450 14451Arguments: 14452"""""""""" 14453 14454The arguments and return value are floating-point numbers of the same type. 14455 14456Semantics: 14457"""""""""" 14458 14459Return the same value as a corresponding libm '``fma``' function but without 14460trapping or setting ``errno``. 14461 14462When specified with the fast-math-flag 'afn', the result may be approximated 14463using a less accurate calculation. 14464 14465'``llvm.fabs.*``' Intrinsic 14466^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14467 14468Syntax: 14469""""""" 14470 14471This is an overloaded intrinsic. You can use ``llvm.fabs`` on any 14472floating-point or vector of floating-point type. Not all targets support 14473all types however. 14474 14475:: 14476 14477 declare float @llvm.fabs.f32(float %Val) 14478 declare double @llvm.fabs.f64(double %Val) 14479 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val) 14480 declare fp128 @llvm.fabs.f128(fp128 %Val) 14481 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val) 14482 14483Overview: 14484""""""""" 14485 14486The '``llvm.fabs.*``' intrinsics return the absolute value of the 14487operand. 14488 14489Arguments: 14490"""""""""" 14491 14492The argument and return value are floating-point numbers of the same 14493type. 14494 14495Semantics: 14496"""""""""" 14497 14498This function returns the same values as the libm ``fabs`` functions 14499would, and handles error conditions in the same way. 14500 14501'``llvm.minnum.*``' Intrinsic 14502^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14503 14504Syntax: 14505""""""" 14506 14507This is an overloaded intrinsic. You can use ``llvm.minnum`` on any 14508floating-point or vector of floating-point type. Not all targets support 14509all types however. 14510 14511:: 14512 14513 declare float @llvm.minnum.f32(float %Val0, float %Val1) 14514 declare double @llvm.minnum.f64(double %Val0, double %Val1) 14515 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14516 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1) 14517 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14518 14519Overview: 14520""""""""" 14521 14522The '``llvm.minnum.*``' intrinsics return the minimum of the two 14523arguments. 14524 14525 14526Arguments: 14527"""""""""" 14528 14529The arguments and return value are floating-point numbers of the same 14530type. 14531 14532Semantics: 14533"""""""""" 14534 14535Follows the IEEE-754 semantics for minNum, except for handling of 14536signaling NaNs. This match's the behavior of libm's fmin. 14537 14538If either operand is a NaN, returns the other non-NaN operand. Returns 14539NaN only if both operands are NaN. The returned NaN is always 14540quiet. If the operands compare equal, returns a value that compares 14541equal to both operands. This means that fmin(+/-0.0, +/-0.0) could 14542return either -0.0 or 0.0. 14543 14544Unlike the IEEE-754 2008 behavior, this does not distinguish between 14545signaling and quiet NaN inputs. If a target's implementation follows 14546the standard and returns a quiet NaN if either input is a signaling 14547NaN, the intrinsic lowering is responsible for quieting the inputs to 14548correctly return the non-NaN input (e.g. by using the equivalent of 14549``llvm.canonicalize``). 14550 14551 14552'``llvm.maxnum.*``' Intrinsic 14553^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14554 14555Syntax: 14556""""""" 14557 14558This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any 14559floating-point or vector of floating-point type. Not all targets support 14560all types however. 14561 14562:: 14563 14564 declare float @llvm.maxnum.f32(float %Val0, float %Val1) 14565 declare double @llvm.maxnum.f64(double %Val0, double %Val1) 14566 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14567 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1) 14568 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14569 14570Overview: 14571""""""""" 14572 14573The '``llvm.maxnum.*``' intrinsics return the maximum of the two 14574arguments. 14575 14576 14577Arguments: 14578"""""""""" 14579 14580The arguments and return value are floating-point numbers of the same 14581type. 14582 14583Semantics: 14584"""""""""" 14585Follows the IEEE-754 semantics for maxNum except for the handling of 14586signaling NaNs. This matches the behavior of libm's fmax. 14587 14588If either operand is a NaN, returns the other non-NaN operand. Returns 14589NaN only if both operands are NaN. The returned NaN is always 14590quiet. If the operands compare equal, returns a value that compares 14591equal to both operands. This means that fmax(+/-0.0, +/-0.0) could 14592return either -0.0 or 0.0. 14593 14594Unlike the IEEE-754 2008 behavior, this does not distinguish between 14595signaling and quiet NaN inputs. If a target's implementation follows 14596the standard and returns a quiet NaN if either input is a signaling 14597NaN, the intrinsic lowering is responsible for quieting the inputs to 14598correctly return the non-NaN input (e.g. by using the equivalent of 14599``llvm.canonicalize``). 14600 14601'``llvm.minimum.*``' Intrinsic 14602^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14603 14604Syntax: 14605""""""" 14606 14607This is an overloaded intrinsic. You can use ``llvm.minimum`` on any 14608floating-point or vector of floating-point type. Not all targets support 14609all types however. 14610 14611:: 14612 14613 declare float @llvm.minimum.f32(float %Val0, float %Val1) 14614 declare double @llvm.minimum.f64(double %Val0, double %Val1) 14615 declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14616 declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1) 14617 declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14618 14619Overview: 14620""""""""" 14621 14622The '``llvm.minimum.*``' intrinsics return the minimum of the two 14623arguments, propagating NaNs and treating -0.0 as less than +0.0. 14624 14625 14626Arguments: 14627"""""""""" 14628 14629The arguments and return value are floating-point numbers of the same 14630type. 14631 14632Semantics: 14633"""""""""" 14634If either operand is a NaN, returns NaN. Otherwise returns the lesser 14635of the two arguments. -0.0 is considered to be less than +0.0 for this 14636intrinsic. Note that these are the semantics specified in the draft of 14637IEEE 754-2018. 14638 14639'``llvm.maximum.*``' Intrinsic 14640^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14641 14642Syntax: 14643""""""" 14644 14645This is an overloaded intrinsic. You can use ``llvm.maximum`` on any 14646floating-point or vector of floating-point type. Not all targets support 14647all types however. 14648 14649:: 14650 14651 declare float @llvm.maximum.f32(float %Val0, float %Val1) 14652 declare double @llvm.maximum.f64(double %Val0, double %Val1) 14653 declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14654 declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1) 14655 declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14656 14657Overview: 14658""""""""" 14659 14660The '``llvm.maximum.*``' intrinsics return the maximum of the two 14661arguments, propagating NaNs and treating -0.0 as less than +0.0. 14662 14663 14664Arguments: 14665"""""""""" 14666 14667The arguments and return value are floating-point numbers of the same 14668type. 14669 14670Semantics: 14671"""""""""" 14672If either operand is a NaN, returns NaN. Otherwise returns the greater 14673of the two arguments. -0.0 is considered to be less than +0.0 for this 14674intrinsic. Note that these are the semantics specified in the draft of 14675IEEE 754-2018. 14676 14677'``llvm.copysign.*``' Intrinsic 14678^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14679 14680Syntax: 14681""""""" 14682 14683This is an overloaded intrinsic. You can use ``llvm.copysign`` on any 14684floating-point or vector of floating-point type. Not all targets support 14685all types however. 14686 14687:: 14688 14689 declare float @llvm.copysign.f32(float %Mag, float %Sgn) 14690 declare double @llvm.copysign.f64(double %Mag, double %Sgn) 14691 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn) 14692 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn) 14693 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn) 14694 14695Overview: 14696""""""""" 14697 14698The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the 14699first operand and the sign of the second operand. 14700 14701Arguments: 14702"""""""""" 14703 14704The arguments and return value are floating-point numbers of the same 14705type. 14706 14707Semantics: 14708"""""""""" 14709 14710This function returns the same values as the libm ``copysign`` 14711functions would, and handles error conditions in the same way. 14712 14713'``llvm.floor.*``' Intrinsic 14714^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14715 14716Syntax: 14717""""""" 14718 14719This is an overloaded intrinsic. You can use ``llvm.floor`` on any 14720floating-point or vector of floating-point type. Not all targets support 14721all types however. 14722 14723:: 14724 14725 declare float @llvm.floor.f32(float %Val) 14726 declare double @llvm.floor.f64(double %Val) 14727 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val) 14728 declare fp128 @llvm.floor.f128(fp128 %Val) 14729 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val) 14730 14731Overview: 14732""""""""" 14733 14734The '``llvm.floor.*``' intrinsics return the floor of the operand. 14735 14736Arguments: 14737"""""""""" 14738 14739The argument and return value are floating-point numbers of the same 14740type. 14741 14742Semantics: 14743"""""""""" 14744 14745This function returns the same values as the libm ``floor`` functions 14746would, and handles error conditions in the same way. 14747 14748'``llvm.ceil.*``' Intrinsic 14749^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14750 14751Syntax: 14752""""""" 14753 14754This is an overloaded intrinsic. You can use ``llvm.ceil`` on any 14755floating-point or vector of floating-point type. Not all targets support 14756all types however. 14757 14758:: 14759 14760 declare float @llvm.ceil.f32(float %Val) 14761 declare double @llvm.ceil.f64(double %Val) 14762 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val) 14763 declare fp128 @llvm.ceil.f128(fp128 %Val) 14764 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val) 14765 14766Overview: 14767""""""""" 14768 14769The '``llvm.ceil.*``' intrinsics return the ceiling of the operand. 14770 14771Arguments: 14772"""""""""" 14773 14774The argument and return value are floating-point numbers of the same 14775type. 14776 14777Semantics: 14778"""""""""" 14779 14780This function returns the same values as the libm ``ceil`` functions 14781would, and handles error conditions in the same way. 14782 14783'``llvm.trunc.*``' Intrinsic 14784^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14785 14786Syntax: 14787""""""" 14788 14789This is an overloaded intrinsic. You can use ``llvm.trunc`` on any 14790floating-point or vector of floating-point type. Not all targets support 14791all types however. 14792 14793:: 14794 14795 declare float @llvm.trunc.f32(float %Val) 14796 declare double @llvm.trunc.f64(double %Val) 14797 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val) 14798 declare fp128 @llvm.trunc.f128(fp128 %Val) 14799 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val) 14800 14801Overview: 14802""""""""" 14803 14804The '``llvm.trunc.*``' intrinsics returns the operand rounded to the 14805nearest integer not larger in magnitude than the operand. 14806 14807Arguments: 14808"""""""""" 14809 14810The argument and return value are floating-point numbers of the same 14811type. 14812 14813Semantics: 14814"""""""""" 14815 14816This function returns the same values as the libm ``trunc`` functions 14817would, and handles error conditions in the same way. 14818 14819'``llvm.rint.*``' Intrinsic 14820^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14821 14822Syntax: 14823""""""" 14824 14825This is an overloaded intrinsic. You can use ``llvm.rint`` on any 14826floating-point or vector of floating-point type. Not all targets support 14827all types however. 14828 14829:: 14830 14831 declare float @llvm.rint.f32(float %Val) 14832 declare double @llvm.rint.f64(double %Val) 14833 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val) 14834 declare fp128 @llvm.rint.f128(fp128 %Val) 14835 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val) 14836 14837Overview: 14838""""""""" 14839 14840The '``llvm.rint.*``' intrinsics returns the operand rounded to the 14841nearest integer. It may raise an inexact floating-point exception if the 14842operand isn't an integer. 14843 14844Arguments: 14845"""""""""" 14846 14847The argument and return value are floating-point numbers of the same 14848type. 14849 14850Semantics: 14851"""""""""" 14852 14853This function returns the same values as the libm ``rint`` functions 14854would, and handles error conditions in the same way. 14855 14856'``llvm.nearbyint.*``' Intrinsic 14857^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14858 14859Syntax: 14860""""""" 14861 14862This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any 14863floating-point or vector of floating-point type. Not all targets support 14864all types however. 14865 14866:: 14867 14868 declare float @llvm.nearbyint.f32(float %Val) 14869 declare double @llvm.nearbyint.f64(double %Val) 14870 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val) 14871 declare fp128 @llvm.nearbyint.f128(fp128 %Val) 14872 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val) 14873 14874Overview: 14875""""""""" 14876 14877The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the 14878nearest integer. 14879 14880Arguments: 14881"""""""""" 14882 14883The argument and return value are floating-point numbers of the same 14884type. 14885 14886Semantics: 14887"""""""""" 14888 14889This function returns the same values as the libm ``nearbyint`` 14890functions would, and handles error conditions in the same way. 14891 14892'``llvm.round.*``' Intrinsic 14893^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14894 14895Syntax: 14896""""""" 14897 14898This is an overloaded intrinsic. You can use ``llvm.round`` on any 14899floating-point or vector of floating-point type. Not all targets support 14900all types however. 14901 14902:: 14903 14904 declare float @llvm.round.f32(float %Val) 14905 declare double @llvm.round.f64(double %Val) 14906 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val) 14907 declare fp128 @llvm.round.f128(fp128 %Val) 14908 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val) 14909 14910Overview: 14911""""""""" 14912 14913The '``llvm.round.*``' intrinsics returns the operand rounded to the 14914nearest integer. 14915 14916Arguments: 14917"""""""""" 14918 14919The argument and return value are floating-point numbers of the same 14920type. 14921 14922Semantics: 14923"""""""""" 14924 14925This function returns the same values as the libm ``round`` 14926functions would, and handles error conditions in the same way. 14927 14928'``llvm.roundeven.*``' Intrinsic 14929^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14930 14931Syntax: 14932""""""" 14933 14934This is an overloaded intrinsic. You can use ``llvm.roundeven`` on any 14935floating-point or vector of floating-point type. Not all targets support 14936all types however. 14937 14938:: 14939 14940 declare float @llvm.roundeven.f32(float %Val) 14941 declare double @llvm.roundeven.f64(double %Val) 14942 declare x86_fp80 @llvm.roundeven.f80(x86_fp80 %Val) 14943 declare fp128 @llvm.roundeven.f128(fp128 %Val) 14944 declare ppc_fp128 @llvm.roundeven.ppcf128(ppc_fp128 %Val) 14945 14946Overview: 14947""""""""" 14948 14949The '``llvm.roundeven.*``' intrinsics returns the operand rounded to the nearest 14950integer in floating-point format rounding halfway cases to even (that is, to the 14951nearest value that is an even integer). 14952 14953Arguments: 14954"""""""""" 14955 14956The argument and return value are floating-point numbers of the same type. 14957 14958Semantics: 14959"""""""""" 14960 14961This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It 14962also behaves in the same way as C standard function ``roundeven``, except that 14963it does not raise floating point exceptions. 14964 14965 14966'``llvm.lround.*``' Intrinsic 14967^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14968 14969Syntax: 14970""""""" 14971 14972This is an overloaded intrinsic. You can use ``llvm.lround`` on any 14973floating-point type. Not all targets support all types however. 14974 14975:: 14976 14977 declare i32 @llvm.lround.i32.f32(float %Val) 14978 declare i32 @llvm.lround.i32.f64(double %Val) 14979 declare i32 @llvm.lround.i32.f80(float %Val) 14980 declare i32 @llvm.lround.i32.f128(double %Val) 14981 declare i32 @llvm.lround.i32.ppcf128(double %Val) 14982 14983 declare i64 @llvm.lround.i64.f32(float %Val) 14984 declare i64 @llvm.lround.i64.f64(double %Val) 14985 declare i64 @llvm.lround.i64.f80(float %Val) 14986 declare i64 @llvm.lround.i64.f128(double %Val) 14987 declare i64 @llvm.lround.i64.ppcf128(double %Val) 14988 14989Overview: 14990""""""""" 14991 14992The '``llvm.lround.*``' intrinsics return the operand rounded to the nearest 14993integer with ties away from zero. 14994 14995 14996Arguments: 14997"""""""""" 14998 14999The argument is a floating-point number and the return value is an integer 15000type. 15001 15002Semantics: 15003"""""""""" 15004 15005This function returns the same values as the libm ``lround`` 15006functions would, but without setting errno. 15007 15008'``llvm.llround.*``' Intrinsic 15009^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15010 15011Syntax: 15012""""""" 15013 15014This is an overloaded intrinsic. You can use ``llvm.llround`` on any 15015floating-point type. Not all targets support all types however. 15016 15017:: 15018 15019 declare i64 @llvm.lround.i64.f32(float %Val) 15020 declare i64 @llvm.lround.i64.f64(double %Val) 15021 declare i64 @llvm.lround.i64.f80(float %Val) 15022 declare i64 @llvm.lround.i64.f128(double %Val) 15023 declare i64 @llvm.lround.i64.ppcf128(double %Val) 15024 15025Overview: 15026""""""""" 15027 15028The '``llvm.llround.*``' intrinsics return the operand rounded to the nearest 15029integer with ties away from zero. 15030 15031Arguments: 15032"""""""""" 15033 15034The argument is a floating-point number and the return value is an integer 15035type. 15036 15037Semantics: 15038"""""""""" 15039 15040This function returns the same values as the libm ``llround`` 15041functions would, but without setting errno. 15042 15043'``llvm.lrint.*``' Intrinsic 15044^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15045 15046Syntax: 15047""""""" 15048 15049This is an overloaded intrinsic. You can use ``llvm.lrint`` on any 15050floating-point type. Not all targets support all types however. 15051 15052:: 15053 15054 declare i32 @llvm.lrint.i32.f32(float %Val) 15055 declare i32 @llvm.lrint.i32.f64(double %Val) 15056 declare i32 @llvm.lrint.i32.f80(float %Val) 15057 declare i32 @llvm.lrint.i32.f128(double %Val) 15058 declare i32 @llvm.lrint.i32.ppcf128(double %Val) 15059 15060 declare i64 @llvm.lrint.i64.f32(float %Val) 15061 declare i64 @llvm.lrint.i64.f64(double %Val) 15062 declare i64 @llvm.lrint.i64.f80(float %Val) 15063 declare i64 @llvm.lrint.i64.f128(double %Val) 15064 declare i64 @llvm.lrint.i64.ppcf128(double %Val) 15065 15066Overview: 15067""""""""" 15068 15069The '``llvm.lrint.*``' intrinsics return the operand rounded to the nearest 15070integer. 15071 15072 15073Arguments: 15074"""""""""" 15075 15076The argument is a floating-point number and the return value is an integer 15077type. 15078 15079Semantics: 15080"""""""""" 15081 15082This function returns the same values as the libm ``lrint`` 15083functions would, but without setting errno. 15084 15085'``llvm.llrint.*``' Intrinsic 15086^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15087 15088Syntax: 15089""""""" 15090 15091This is an overloaded intrinsic. You can use ``llvm.llrint`` on any 15092floating-point type. Not all targets support all types however. 15093 15094:: 15095 15096 declare i64 @llvm.llrint.i64.f32(float %Val) 15097 declare i64 @llvm.llrint.i64.f64(double %Val) 15098 declare i64 @llvm.llrint.i64.f80(float %Val) 15099 declare i64 @llvm.llrint.i64.f128(double %Val) 15100 declare i64 @llvm.llrint.i64.ppcf128(double %Val) 15101 15102Overview: 15103""""""""" 15104 15105The '``llvm.llrint.*``' intrinsics return the operand rounded to the nearest 15106integer. 15107 15108Arguments: 15109"""""""""" 15110 15111The argument is a floating-point number and the return value is an integer 15112type. 15113 15114Semantics: 15115"""""""""" 15116 15117This function returns the same values as the libm ``llrint`` 15118functions would, but without setting errno. 15119 15120Bit Manipulation Intrinsics 15121--------------------------- 15122 15123LLVM provides intrinsics for a few important bit manipulation 15124operations. These allow efficient code generation for some algorithms. 15125 15126'``llvm.bitreverse.*``' Intrinsics 15127^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15128 15129Syntax: 15130""""""" 15131 15132This is an overloaded intrinsic function. You can use bitreverse on any 15133integer type. 15134 15135:: 15136 15137 declare i16 @llvm.bitreverse.i16(i16 <id>) 15138 declare i32 @llvm.bitreverse.i32(i32 <id>) 15139 declare i64 @llvm.bitreverse.i64(i64 <id>) 15140 declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>) 15141 15142Overview: 15143""""""""" 15144 15145The '``llvm.bitreverse``' family of intrinsics is used to reverse the 15146bitpattern of an integer value or vector of integer values; for example 15147``0b10110110`` becomes ``0b01101101``. 15148 15149Semantics: 15150"""""""""" 15151 15152The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit 15153``M`` in the input moved to bit ``N-M-1`` in the output. The vector 15154intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element 15155basis and the element order is not affected. 15156 15157'``llvm.bswap.*``' Intrinsics 15158^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15159 15160Syntax: 15161""""""" 15162 15163This is an overloaded intrinsic function. You can use bswap on any 15164integer type that is an even number of bytes (i.e. BitWidth % 16 == 0). 15165 15166:: 15167 15168 declare i16 @llvm.bswap.i16(i16 <id>) 15169 declare i32 @llvm.bswap.i32(i32 <id>) 15170 declare i64 @llvm.bswap.i64(i64 <id>) 15171 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>) 15172 15173Overview: 15174""""""""" 15175 15176The '``llvm.bswap``' family of intrinsics is used to byte swap an integer 15177value or vector of integer values with an even number of bytes (positive 15178multiple of 16 bits). 15179 15180Semantics: 15181"""""""""" 15182 15183The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high 15184and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32`` 15185intrinsic returns an i32 value that has the four bytes of the input i32 15186swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the 15187returned i32 will have its bytes in 3, 2, 1, 0 order. The 15188``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this 15189concept to additional even-byte lengths (6 bytes, 8 bytes and more, 15190respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``, 15191operate on a per-element basis and the element order is not affected. 15192 15193'``llvm.ctpop.*``' Intrinsic 15194^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15195 15196Syntax: 15197""""""" 15198 15199This is an overloaded intrinsic. You can use llvm.ctpop on any integer 15200bit width, or on any vector with integer elements. Not all targets 15201support all bit widths or vector types, however. 15202 15203:: 15204 15205 declare i8 @llvm.ctpop.i8(i8 <src>) 15206 declare i16 @llvm.ctpop.i16(i16 <src>) 15207 declare i32 @llvm.ctpop.i32(i32 <src>) 15208 declare i64 @llvm.ctpop.i64(i64 <src>) 15209 declare i256 @llvm.ctpop.i256(i256 <src>) 15210 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>) 15211 15212Overview: 15213""""""""" 15214 15215The '``llvm.ctpop``' family of intrinsics counts the number of bits set 15216in a value. 15217 15218Arguments: 15219"""""""""" 15220 15221The only argument is the value to be counted. The argument may be of any 15222integer type, or a vector with integer elements. The return type must 15223match the argument type. 15224 15225Semantics: 15226"""""""""" 15227 15228The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within 15229each element of a vector. 15230 15231'``llvm.ctlz.*``' Intrinsic 15232^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15233 15234Syntax: 15235""""""" 15236 15237This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any 15238integer bit width, or any vector whose elements are integers. Not all 15239targets support all bit widths or vector types, however. 15240 15241:: 15242 15243 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_poison>) 15244 declare <2 x i37> @llvm.ctlz.v2i37(<2 x i37> <src>, i1 <is_zero_poison>) 15245 15246Overview: 15247""""""""" 15248 15249The '``llvm.ctlz``' family of intrinsic functions counts the number of 15250leading zeros in a variable. 15251 15252Arguments: 15253"""""""""" 15254 15255The first argument is the value to be counted. This argument may be of 15256any integer type, or a vector with integer element type. The return 15257type must match the first argument type. 15258 15259The second argument is a constant flag that indicates whether the intrinsic 15260returns a valid result if the first argument is zero. If the first 15261argument is zero and the second argument is true, the result is poison. 15262Historically some architectures did not provide a defined result for zero 15263values as efficiently, and many algorithms are now predicated on avoiding 15264zero-value inputs. 15265 15266Semantics: 15267"""""""""" 15268 15269The '``llvm.ctlz``' intrinsic counts the leading (most significant) 15270zeros in a variable, or within each element of the vector. If 15271``src == 0`` then the result is the size in bits of the type of ``src`` 15272if ``is_zero_poison == 0`` and ``poison`` otherwise. For example, 15273``llvm.ctlz(i32 2) = 30``. 15274 15275'``llvm.cttz.*``' Intrinsic 15276^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15277 15278Syntax: 15279""""""" 15280 15281This is an overloaded intrinsic. You can use ``llvm.cttz`` on any 15282integer bit width, or any vector of integer elements. Not all targets 15283support all bit widths or vector types, however. 15284 15285:: 15286 15287 declare i42 @llvm.cttz.i42 (i42 <src>, i1 <is_zero_poison>) 15288 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_poison>) 15289 15290Overview: 15291""""""""" 15292 15293The '``llvm.cttz``' family of intrinsic functions counts the number of 15294trailing zeros. 15295 15296Arguments: 15297"""""""""" 15298 15299The first argument is the value to be counted. This argument may be of 15300any integer type, or a vector with integer element type. The return 15301type must match the first argument type. 15302 15303The second argument is a constant flag that indicates whether the intrinsic 15304returns a valid result if the first argument is zero. If the first 15305argument is zero and the second argument is true, the result is poison. 15306Historically some architectures did not provide a defined result for zero 15307values as efficiently, and many algorithms are now predicated on avoiding 15308zero-value inputs. 15309 15310Semantics: 15311"""""""""" 15312 15313The '``llvm.cttz``' intrinsic counts the trailing (least significant) 15314zeros in a variable, or within each element of a vector. If ``src == 0`` 15315then the result is the size in bits of the type of ``src`` if 15316``is_zero_poison == 0`` and ``poison`` otherwise. For example, 15317``llvm.cttz(2) = 1``. 15318 15319.. _int_overflow: 15320 15321'``llvm.fshl.*``' Intrinsic 15322^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15323 15324Syntax: 15325""""""" 15326 15327This is an overloaded intrinsic. You can use ``llvm.fshl`` on any 15328integer bit width or any vector of integer elements. Not all targets 15329support all bit widths or vector types, however. 15330 15331:: 15332 15333 declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c) 15334 declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c) 15335 declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) 15336 15337Overview: 15338""""""""" 15339 15340The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left: 15341the first two values are concatenated as { %a : %b } (%a is the most significant 15342bits of the wide value), the combined value is shifted left, and the most 15343significant bits are extracted to produce a result that is the same size as the 15344original arguments. If the first 2 arguments are identical, this is equivalent 15345to a rotate left operation. For vector types, the operation occurs for each 15346element of the vector. The shift argument is treated as an unsigned amount 15347modulo the element size of the arguments. 15348 15349Arguments: 15350"""""""""" 15351 15352The first two arguments are the values to be concatenated. The third 15353argument is the shift amount. The arguments may be any integer type or a 15354vector with integer element type. All arguments and the return value must 15355have the same type. 15356 15357Example: 15358"""""""" 15359 15360.. code-block:: text 15361 15362 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8) 15363 %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000) 15364 %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000) 15365 %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000) 15366 15367'``llvm.fshr.*``' Intrinsic 15368^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15369 15370Syntax: 15371""""""" 15372 15373This is an overloaded intrinsic. You can use ``llvm.fshr`` on any 15374integer bit width or any vector of integer elements. Not all targets 15375support all bit widths or vector types, however. 15376 15377:: 15378 15379 declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c) 15380 declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c) 15381 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) 15382 15383Overview: 15384""""""""" 15385 15386The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right: 15387the first two values are concatenated as { %a : %b } (%a is the most significant 15388bits of the wide value), the combined value is shifted right, and the least 15389significant bits are extracted to produce a result that is the same size as the 15390original arguments. If the first 2 arguments are identical, this is equivalent 15391to a rotate right operation. For vector types, the operation occurs for each 15392element of the vector. The shift argument is treated as an unsigned amount 15393modulo the element size of the arguments. 15394 15395Arguments: 15396"""""""""" 15397 15398The first two arguments are the values to be concatenated. The third 15399argument is the shift amount. The arguments may be any integer type or a 15400vector with integer element type. All arguments and the return value must 15401have the same type. 15402 15403Example: 15404"""""""" 15405 15406.. code-block:: text 15407 15408 %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8) 15409 %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110) 15410 %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001) 15411 %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111) 15412 15413Arithmetic with Overflow Intrinsics 15414----------------------------------- 15415 15416LLVM provides intrinsics for fast arithmetic overflow checking. 15417 15418Each of these intrinsics returns a two-element struct. The first 15419element of this struct contains the result of the corresponding 15420arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of 15421the result. Therefore, for example, the first element of the struct 15422returned by ``llvm.sadd.with.overflow.i32`` is always the same as the 15423result of a 32-bit ``add`` instruction with the same operands, where 15424the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag. 15425 15426The second element of the result is an ``i1`` that is 1 if the 15427arithmetic operation overflowed and 0 otherwise. An operation 15428overflows if, for any values of its operands ``A`` and ``B`` and for 15429any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is 15430not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is 15431``sext`` for signed overflow and ``zext`` for unsigned overflow, and 15432``op`` is the underlying arithmetic operation. 15433 15434The behavior of these intrinsics is well-defined for all argument 15435values. 15436 15437'``llvm.sadd.with.overflow.*``' Intrinsics 15438^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15439 15440Syntax: 15441""""""" 15442 15443This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow`` 15444on any integer bit width or vectors of integers. 15445 15446:: 15447 15448 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b) 15449 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 15450 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b) 15451 declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15452 15453Overview: 15454""""""""" 15455 15456The '``llvm.sadd.with.overflow``' family of intrinsic functions perform 15457a signed addition of the two arguments, and indicate whether an overflow 15458occurred during the signed summation. 15459 15460Arguments: 15461"""""""""" 15462 15463The arguments (%a and %b) and the first element of the result structure 15464may be of integer types of any bit width, but they must have the same 15465bit width. The second element of the result structure must be of type 15466``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15467addition. 15468 15469Semantics: 15470"""""""""" 15471 15472The '``llvm.sadd.with.overflow``' family of intrinsic functions perform 15473a signed addition of the two variables. They return a structure --- the 15474first element of which is the signed summation, and the second element 15475of which is a bit specifying if the signed summation resulted in an 15476overflow. 15477 15478Examples: 15479""""""""" 15480 15481.. code-block:: llvm 15482 15483 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 15484 %sum = extractvalue {i32, i1} %res, 0 15485 %obit = extractvalue {i32, i1} %res, 1 15486 br i1 %obit, label %overflow, label %normal 15487 15488'``llvm.uadd.with.overflow.*``' Intrinsics 15489^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15490 15491Syntax: 15492""""""" 15493 15494This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow`` 15495on any integer bit width or vectors of integers. 15496 15497:: 15498 15499 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b) 15500 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 15501 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b) 15502 declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15503 15504Overview: 15505""""""""" 15506 15507The '``llvm.uadd.with.overflow``' family of intrinsic functions perform 15508an unsigned addition of the two arguments, and indicate whether a carry 15509occurred during the unsigned summation. 15510 15511Arguments: 15512"""""""""" 15513 15514The arguments (%a and %b) and the first element of the result structure 15515may be of integer types of any bit width, but they must have the same 15516bit width. The second element of the result structure must be of type 15517``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15518addition. 15519 15520Semantics: 15521"""""""""" 15522 15523The '``llvm.uadd.with.overflow``' family of intrinsic functions perform 15524an unsigned addition of the two arguments. They return a structure --- the 15525first element of which is the sum, and the second element of which is a 15526bit specifying if the unsigned summation resulted in a carry. 15527 15528Examples: 15529""""""""" 15530 15531.. code-block:: llvm 15532 15533 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 15534 %sum = extractvalue {i32, i1} %res, 0 15535 %obit = extractvalue {i32, i1} %res, 1 15536 br i1 %obit, label %carry, label %normal 15537 15538'``llvm.ssub.with.overflow.*``' Intrinsics 15539^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15540 15541Syntax: 15542""""""" 15543 15544This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow`` 15545on any integer bit width or vectors of integers. 15546 15547:: 15548 15549 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b) 15550 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 15551 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b) 15552 declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15553 15554Overview: 15555""""""""" 15556 15557The '``llvm.ssub.with.overflow``' family of intrinsic functions perform 15558a signed subtraction of the two arguments, and indicate whether an 15559overflow occurred during the signed subtraction. 15560 15561Arguments: 15562"""""""""" 15563 15564The arguments (%a and %b) and the first element of the result structure 15565may be of integer types of any bit width, but they must have the same 15566bit width. The second element of the result structure must be of type 15567``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15568subtraction. 15569 15570Semantics: 15571"""""""""" 15572 15573The '``llvm.ssub.with.overflow``' family of intrinsic functions perform 15574a signed subtraction of the two arguments. They return a structure --- the 15575first element of which is the subtraction, and the second element of 15576which is a bit specifying if the signed subtraction resulted in an 15577overflow. 15578 15579Examples: 15580""""""""" 15581 15582.. code-block:: llvm 15583 15584 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 15585 %sum = extractvalue {i32, i1} %res, 0 15586 %obit = extractvalue {i32, i1} %res, 1 15587 br i1 %obit, label %overflow, label %normal 15588 15589'``llvm.usub.with.overflow.*``' Intrinsics 15590^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15591 15592Syntax: 15593""""""" 15594 15595This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow`` 15596on any integer bit width or vectors of integers. 15597 15598:: 15599 15600 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b) 15601 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 15602 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b) 15603 declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15604 15605Overview: 15606""""""""" 15607 15608The '``llvm.usub.with.overflow``' family of intrinsic functions perform 15609an unsigned subtraction of the two arguments, and indicate whether an 15610overflow occurred during the unsigned subtraction. 15611 15612Arguments: 15613"""""""""" 15614 15615The arguments (%a and %b) and the first element of the result structure 15616may be of integer types of any bit width, but they must have the same 15617bit width. The second element of the result structure must be of type 15618``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15619subtraction. 15620 15621Semantics: 15622"""""""""" 15623 15624The '``llvm.usub.with.overflow``' family of intrinsic functions perform 15625an unsigned subtraction of the two arguments. They return a structure --- 15626the first element of which is the subtraction, and the second element of 15627which is a bit specifying if the unsigned subtraction resulted in an 15628overflow. 15629 15630Examples: 15631""""""""" 15632 15633.. code-block:: llvm 15634 15635 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 15636 %sum = extractvalue {i32, i1} %res, 0 15637 %obit = extractvalue {i32, i1} %res, 1 15638 br i1 %obit, label %overflow, label %normal 15639 15640'``llvm.smul.with.overflow.*``' Intrinsics 15641^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15642 15643Syntax: 15644""""""" 15645 15646This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow`` 15647on any integer bit width or vectors of integers. 15648 15649:: 15650 15651 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b) 15652 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 15653 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b) 15654 declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15655 15656Overview: 15657""""""""" 15658 15659The '``llvm.smul.with.overflow``' family of intrinsic functions perform 15660a signed multiplication of the two arguments, and indicate whether an 15661overflow occurred during the signed multiplication. 15662 15663Arguments: 15664"""""""""" 15665 15666The arguments (%a and %b) and the first element of the result structure 15667may be of integer types of any bit width, but they must have the same 15668bit width. The second element of the result structure must be of type 15669``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15670multiplication. 15671 15672Semantics: 15673"""""""""" 15674 15675The '``llvm.smul.with.overflow``' family of intrinsic functions perform 15676a signed multiplication of the two arguments. They return a structure --- 15677the first element of which is the multiplication, and the second element 15678of which is a bit specifying if the signed multiplication resulted in an 15679overflow. 15680 15681Examples: 15682""""""""" 15683 15684.. code-block:: llvm 15685 15686 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 15687 %sum = extractvalue {i32, i1} %res, 0 15688 %obit = extractvalue {i32, i1} %res, 1 15689 br i1 %obit, label %overflow, label %normal 15690 15691'``llvm.umul.with.overflow.*``' Intrinsics 15692^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15693 15694Syntax: 15695""""""" 15696 15697This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow`` 15698on any integer bit width or vectors of integers. 15699 15700:: 15701 15702 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b) 15703 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 15704 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b) 15705 declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15706 15707Overview: 15708""""""""" 15709 15710The '``llvm.umul.with.overflow``' family of intrinsic functions perform 15711a unsigned multiplication of the two arguments, and indicate whether an 15712overflow occurred during the unsigned multiplication. 15713 15714Arguments: 15715"""""""""" 15716 15717The arguments (%a and %b) and the first element of the result structure 15718may be of integer types of any bit width, but they must have the same 15719bit width. The second element of the result structure must be of type 15720``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15721multiplication. 15722 15723Semantics: 15724"""""""""" 15725 15726The '``llvm.umul.with.overflow``' family of intrinsic functions perform 15727an unsigned multiplication of the two arguments. They return a structure --- 15728the first element of which is the multiplication, and the second 15729element of which is a bit specifying if the unsigned multiplication 15730resulted in an overflow. 15731 15732Examples: 15733""""""""" 15734 15735.. code-block:: llvm 15736 15737 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 15738 %sum = extractvalue {i32, i1} %res, 0 15739 %obit = extractvalue {i32, i1} %res, 1 15740 br i1 %obit, label %overflow, label %normal 15741 15742Saturation Arithmetic Intrinsics 15743--------------------------------- 15744 15745Saturation arithmetic is a version of arithmetic in which operations are 15746limited to a fixed range between a minimum and maximum value. If the result of 15747an operation is greater than the maximum value, the result is set (or 15748"clamped") to this maximum. If it is below the minimum, it is clamped to this 15749minimum. 15750 15751 15752'``llvm.sadd.sat.*``' Intrinsics 15753^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15754 15755Syntax 15756""""""" 15757 15758This is an overloaded intrinsic. You can use ``llvm.sadd.sat`` 15759on any integer bit width or vectors of integers. 15760 15761:: 15762 15763 declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b) 15764 declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b) 15765 declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b) 15766 declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15767 15768Overview 15769""""""""" 15770 15771The '``llvm.sadd.sat``' family of intrinsic functions perform signed 15772saturating addition on the 2 arguments. 15773 15774Arguments 15775"""""""""" 15776 15777The arguments (%a and %b) and the result may be of integer types of any bit 15778width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15779values that will undergo signed addition. 15780 15781Semantics: 15782"""""""""" 15783 15784The maximum value this operation can clamp to is the largest signed value 15785representable by the bit width of the arguments. The minimum value is the 15786smallest signed value representable by this bit width. 15787 15788 15789Examples 15790""""""""" 15791 15792.. code-block:: llvm 15793 15794 %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3 15795 %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7 15796 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2 15797 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8 15798 15799 15800'``llvm.uadd.sat.*``' Intrinsics 15801^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15802 15803Syntax 15804""""""" 15805 15806This is an overloaded intrinsic. You can use ``llvm.uadd.sat`` 15807on any integer bit width or vectors of integers. 15808 15809:: 15810 15811 declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b) 15812 declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b) 15813 declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b) 15814 declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15815 15816Overview 15817""""""""" 15818 15819The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned 15820saturating addition on the 2 arguments. 15821 15822Arguments 15823"""""""""" 15824 15825The arguments (%a and %b) and the result may be of integer types of any bit 15826width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15827values that will undergo unsigned addition. 15828 15829Semantics: 15830"""""""""" 15831 15832The maximum value this operation can clamp to is the largest unsigned value 15833representable by the bit width of the arguments. Because this is an unsigned 15834operation, the result will never saturate towards zero. 15835 15836 15837Examples 15838""""""""" 15839 15840.. code-block:: llvm 15841 15842 %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3 15843 %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11 15844 %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15 15845 15846 15847'``llvm.ssub.sat.*``' Intrinsics 15848^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15849 15850Syntax 15851""""""" 15852 15853This is an overloaded intrinsic. You can use ``llvm.ssub.sat`` 15854on any integer bit width or vectors of integers. 15855 15856:: 15857 15858 declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b) 15859 declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b) 15860 declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b) 15861 declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15862 15863Overview 15864""""""""" 15865 15866The '``llvm.ssub.sat``' family of intrinsic functions perform signed 15867saturating subtraction on the 2 arguments. 15868 15869Arguments 15870"""""""""" 15871 15872The arguments (%a and %b) and the result may be of integer types of any bit 15873width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15874values that will undergo signed subtraction. 15875 15876Semantics: 15877"""""""""" 15878 15879The maximum value this operation can clamp to is the largest signed value 15880representable by the bit width of the arguments. The minimum value is the 15881smallest signed value representable by this bit width. 15882 15883 15884Examples 15885""""""""" 15886 15887.. code-block:: llvm 15888 15889 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1 15890 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4 15891 %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8 15892 %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7 15893 15894 15895'``llvm.usub.sat.*``' Intrinsics 15896^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15897 15898Syntax 15899""""""" 15900 15901This is an overloaded intrinsic. You can use ``llvm.usub.sat`` 15902on any integer bit width or vectors of integers. 15903 15904:: 15905 15906 declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b) 15907 declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b) 15908 declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b) 15909 declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15910 15911Overview 15912""""""""" 15913 15914The '``llvm.usub.sat``' family of intrinsic functions perform unsigned 15915saturating subtraction on the 2 arguments. 15916 15917Arguments 15918"""""""""" 15919 15920The arguments (%a and %b) and the result may be of integer types of any bit 15921width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15922values that will undergo unsigned subtraction. 15923 15924Semantics: 15925"""""""""" 15926 15927The minimum value this operation can clamp to is 0, which is the smallest 15928unsigned value representable by the bit width of the unsigned arguments. 15929Because this is an unsigned operation, the result will never saturate towards 15930the largest possible value representable by this bit width. 15931 15932 15933Examples 15934""""""""" 15935 15936.. code-block:: llvm 15937 15938 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1 15939 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0 15940 15941 15942'``llvm.sshl.sat.*``' Intrinsics 15943^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15944 15945Syntax 15946""""""" 15947 15948This is an overloaded intrinsic. You can use ``llvm.sshl.sat`` 15949on integers or vectors of integers of any bit width. 15950 15951:: 15952 15953 declare i16 @llvm.sshl.sat.i16(i16 %a, i16 %b) 15954 declare i32 @llvm.sshl.sat.i32(i32 %a, i32 %b) 15955 declare i64 @llvm.sshl.sat.i64(i64 %a, i64 %b) 15956 declare <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15957 15958Overview 15959""""""""" 15960 15961The '``llvm.sshl.sat``' family of intrinsic functions perform signed 15962saturating left shift on the first argument. 15963 15964Arguments 15965"""""""""" 15966 15967The arguments (``%a`` and ``%b``) and the result may be of integer types of any 15968bit width, but they must have the same bit width. ``%a`` is the value to be 15969shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or 15970dynamically) equal to or larger than the integer bit width of the arguments, 15971the result is a :ref:`poison value <poisonvalues>`. If the arguments are 15972vectors, each vector element of ``a`` is shifted by the corresponding shift 15973amount in ``b``. 15974 15975 15976Semantics: 15977"""""""""" 15978 15979The maximum value this operation can clamp to is the largest signed value 15980representable by the bit width of the arguments. The minimum value is the 15981smallest signed value representable by this bit width. 15982 15983 15984Examples 15985""""""""" 15986 15987.. code-block:: llvm 15988 15989 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 1) ; %res = 4 15990 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 2) ; %res = 7 15991 %res = call i4 @llvm.sshl.sat.i4(i4 -5, i4 1) ; %res = -8 15992 %res = call i4 @llvm.sshl.sat.i4(i4 -1, i4 1) ; %res = -2 15993 15994 15995'``llvm.ushl.sat.*``' Intrinsics 15996^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15997 15998Syntax 15999""""""" 16000 16001This is an overloaded intrinsic. You can use ``llvm.ushl.sat`` 16002on integers or vectors of integers of any bit width. 16003 16004:: 16005 16006 declare i16 @llvm.ushl.sat.i16(i16 %a, i16 %b) 16007 declare i32 @llvm.ushl.sat.i32(i32 %a, i32 %b) 16008 declare i64 @llvm.ushl.sat.i64(i64 %a, i64 %b) 16009 declare <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 16010 16011Overview 16012""""""""" 16013 16014The '``llvm.ushl.sat``' family of intrinsic functions perform unsigned 16015saturating left shift on the first argument. 16016 16017Arguments 16018"""""""""" 16019 16020The arguments (``%a`` and ``%b``) and the result may be of integer types of any 16021bit width, but they must have the same bit width. ``%a`` is the value to be 16022shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or 16023dynamically) equal to or larger than the integer bit width of the arguments, 16024the result is a :ref:`poison value <poisonvalues>`. If the arguments are 16025vectors, each vector element of ``a`` is shifted by the corresponding shift 16026amount in ``b``. 16027 16028Semantics: 16029"""""""""" 16030 16031The maximum value this operation can clamp to is the largest unsigned value 16032representable by the bit width of the arguments. 16033 16034 16035Examples 16036""""""""" 16037 16038.. code-block:: llvm 16039 16040 %res = call i4 @llvm.ushl.sat.i4(i4 2, i4 1) ; %res = 4 16041 %res = call i4 @llvm.ushl.sat.i4(i4 3, i4 3) ; %res = 15 16042 16043 16044Fixed Point Arithmetic Intrinsics 16045--------------------------------- 16046 16047A fixed point number represents a real data type for a number that has a fixed 16048number of digits after a radix point (equivalent to the decimal point '.'). 16049The number of digits after the radix point is referred as the `scale`. These 16050are useful for representing fractional values to a specific precision. The 16051following intrinsics perform fixed point arithmetic operations on 2 operands 16052of the same scale, specified as the third argument. 16053 16054The ``llvm.*mul.fix`` family of intrinsic functions represents a multiplication 16055of fixed point numbers through scaled integers. Therefore, fixed point 16056multiplication can be represented as 16057 16058.. code-block:: llvm 16059 16060 %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale) 16061 16062 ; Expands to 16063 %a2 = sext i4 %a to i8 16064 %b2 = sext i4 %b to i8 16065 %mul = mul nsw nuw i8 %a2, %b2 16066 %scale2 = trunc i32 %scale to i8 16067 %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity 16068 %result = trunc i8 %r to i4 16069 16070The ``llvm.*div.fix`` family of intrinsic functions represents a division of 16071fixed point numbers through scaled integers. Fixed point division can be 16072represented as: 16073 16074.. code-block:: llvm 16075 16076 %result call i4 @llvm.sdiv.fix.i4(i4 %a, i4 %b, i32 %scale) 16077 16078 ; Expands to 16079 %a2 = sext i4 %a to i8 16080 %b2 = sext i4 %b to i8 16081 %scale2 = trunc i32 %scale to i8 16082 %a3 = shl i8 %a2, %scale2 16083 %r = sdiv i8 %a3, %b2 ; this is for a target rounding towards zero 16084 %result = trunc i8 %r to i4 16085 16086For each of these functions, if the result cannot be represented exactly with 16087the provided scale, the result is rounded. Rounding is unspecified since 16088preferred rounding may vary for different targets. Rounding is specified 16089through a target hook. Different pipelines should legalize or optimize this 16090using the rounding specified by this hook if it is provided. Operations like 16091constant folding, instruction combining, KnownBits, and ValueTracking should 16092also use this hook, if provided, and not assume the direction of rounding. A 16093rounded result must always be within one unit of precision from the true 16094result. That is, the error between the returned result and the true result must 16095be less than 1/2^(scale). 16096 16097 16098'``llvm.smul.fix.*``' Intrinsics 16099^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16100 16101Syntax 16102""""""" 16103 16104This is an overloaded intrinsic. You can use ``llvm.smul.fix`` 16105on any integer bit width or vectors of integers. 16106 16107:: 16108 16109 declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale) 16110 declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale) 16111 declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale) 16112 declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16113 16114Overview 16115""""""""" 16116 16117The '``llvm.smul.fix``' family of intrinsic functions perform signed 16118fixed point multiplication on 2 arguments of the same scale. 16119 16120Arguments 16121"""""""""" 16122 16123The arguments (%a and %b) and the result may be of integer types of any bit 16124width, but they must have the same bit width. The arguments may also work with 16125int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16126values that will undergo signed fixed point multiplication. The argument 16127``%scale`` represents the scale of both operands, and must be a constant 16128integer. 16129 16130Semantics: 16131"""""""""" 16132 16133This operation performs fixed point multiplication on the 2 arguments of a 16134specified scale. The result will also be returned in the same scale specified 16135in the third argument. 16136 16137If the result value cannot be precisely represented in the given scale, the 16138value is rounded up or down to the closest representable value. The rounding 16139direction is unspecified. 16140 16141It is undefined behavior if the result value does not fit within the range of 16142the fixed point type. 16143 16144 16145Examples 16146""""""""" 16147 16148.. code-block:: llvm 16149 16150 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 16151 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 16152 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5) 16153 16154 ; The result in the following could be rounded up to -2 or down to -2.5 16155 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25) 16156 16157 16158'``llvm.umul.fix.*``' Intrinsics 16159^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16160 16161Syntax 16162""""""" 16163 16164This is an overloaded intrinsic. You can use ``llvm.umul.fix`` 16165on any integer bit width or vectors of integers. 16166 16167:: 16168 16169 declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale) 16170 declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale) 16171 declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale) 16172 declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16173 16174Overview 16175""""""""" 16176 16177The '``llvm.umul.fix``' family of intrinsic functions perform unsigned 16178fixed point multiplication on 2 arguments of the same scale. 16179 16180Arguments 16181"""""""""" 16182 16183The arguments (%a and %b) and the result may be of integer types of any bit 16184width, but they must have the same bit width. The arguments may also work with 16185int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16186values that will undergo unsigned fixed point multiplication. The argument 16187``%scale`` represents the scale of both operands, and must be a constant 16188integer. 16189 16190Semantics: 16191"""""""""" 16192 16193This operation performs unsigned fixed point multiplication on the 2 arguments of a 16194specified scale. The result will also be returned in the same scale specified 16195in the third argument. 16196 16197If the result value cannot be precisely represented in the given scale, the 16198value is rounded up or down to the closest representable value. The rounding 16199direction is unspecified. 16200 16201It is undefined behavior if the result value does not fit within the range of 16202the fixed point type. 16203 16204 16205Examples 16206""""""""" 16207 16208.. code-block:: llvm 16209 16210 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 16211 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 16212 16213 ; The result in the following could be rounded down to 3.5 or up to 4 16214 %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75) 16215 16216 16217'``llvm.smul.fix.sat.*``' Intrinsics 16218^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16219 16220Syntax 16221""""""" 16222 16223This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat`` 16224on any integer bit width or vectors of integers. 16225 16226:: 16227 16228 declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16229 declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16230 declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16231 declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16232 16233Overview 16234""""""""" 16235 16236The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed 16237fixed point saturating multiplication on 2 arguments of the same scale. 16238 16239Arguments 16240"""""""""" 16241 16242The arguments (%a and %b) and the result may be of integer types of any bit 16243width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16244values that will undergo signed fixed point multiplication. The argument 16245``%scale`` represents the scale of both operands, and must be a constant 16246integer. 16247 16248Semantics: 16249"""""""""" 16250 16251This operation performs fixed point multiplication on the 2 arguments of a 16252specified scale. The result will also be returned in the same scale specified 16253in the third argument. 16254 16255If the result value cannot be precisely represented in the given scale, the 16256value is rounded up or down to the closest representable value. The rounding 16257direction is unspecified. 16258 16259The maximum value this operation can clamp to is the largest signed value 16260representable by the bit width of the first 2 arguments. The minimum value is the 16261smallest signed value representable by this bit width. 16262 16263 16264Examples 16265""""""""" 16266 16267.. code-block:: llvm 16268 16269 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 16270 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 16271 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5) 16272 16273 ; The result in the following could be rounded up to -2 or down to -2.5 16274 %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) 16275 16276 ; Saturation 16277 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7 16278 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2) ; %res = 7 16279 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2) ; %res = -8 16280 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1) ; %res = 7 16281 16282 ; Scale can affect the saturation result 16283 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7) 16284 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2) 16285 16286 16287'``llvm.umul.fix.sat.*``' Intrinsics 16288^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16289 16290Syntax 16291""""""" 16292 16293This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat`` 16294on any integer bit width or vectors of integers. 16295 16296:: 16297 16298 declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16299 declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16300 declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16301 declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16302 16303Overview 16304""""""""" 16305 16306The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned 16307fixed point saturating multiplication on 2 arguments of the same scale. 16308 16309Arguments 16310"""""""""" 16311 16312The arguments (%a and %b) and the result may be of integer types of any bit 16313width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16314values that will undergo unsigned fixed point multiplication. The argument 16315``%scale`` represents the scale of both operands, and must be a constant 16316integer. 16317 16318Semantics: 16319"""""""""" 16320 16321This operation performs fixed point multiplication on the 2 arguments of a 16322specified scale. The result will also be returned in the same scale specified 16323in the third argument. 16324 16325If the result value cannot be precisely represented in the given scale, the 16326value is rounded up or down to the closest representable value. The rounding 16327direction is unspecified. 16328 16329The maximum value this operation can clamp to is the largest unsigned value 16330representable by the bit width of the first 2 arguments. The minimum value is the 16331smallest unsigned value representable by this bit width (zero). 16332 16333 16334Examples 16335""""""""" 16336 16337.. code-block:: llvm 16338 16339 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 16340 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 16341 16342 ; The result in the following could be rounded down to 2 or up to 2.5 16343 %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) 16344 16345 ; Saturation 16346 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0) ; %res = 15 (8 x 2 -> clamped to 15) 16347 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2) ; %res = 15 (2 x 2 -> clamped to 3.75) 16348 16349 ; Scale can affect the saturation result 16350 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7) 16351 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2) 16352 16353 16354'``llvm.sdiv.fix.*``' Intrinsics 16355^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16356 16357Syntax 16358""""""" 16359 16360This is an overloaded intrinsic. You can use ``llvm.sdiv.fix`` 16361on any integer bit width or vectors of integers. 16362 16363:: 16364 16365 declare i16 @llvm.sdiv.fix.i16(i16 %a, i16 %b, i32 %scale) 16366 declare i32 @llvm.sdiv.fix.i32(i32 %a, i32 %b, i32 %scale) 16367 declare i64 @llvm.sdiv.fix.i64(i64 %a, i64 %b, i32 %scale) 16368 declare <4 x i32> @llvm.sdiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16369 16370Overview 16371""""""""" 16372 16373The '``llvm.sdiv.fix``' family of intrinsic functions perform signed 16374fixed point division on 2 arguments of the same scale. 16375 16376Arguments 16377"""""""""" 16378 16379The arguments (%a and %b) and the result may be of integer types of any bit 16380width, but they must have the same bit width. The arguments may also work with 16381int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16382values that will undergo signed fixed point division. The argument 16383``%scale`` represents the scale of both operands, and must be a constant 16384integer. 16385 16386Semantics: 16387"""""""""" 16388 16389This operation performs fixed point division on the 2 arguments of a 16390specified scale. The result will also be returned in the same scale specified 16391in the third argument. 16392 16393If the result value cannot be precisely represented in the given scale, the 16394value is rounded up or down to the closest representable value. The rounding 16395direction is unspecified. 16396 16397It is undefined behavior if the result value does not fit within the range of 16398the fixed point type, or if the second argument is zero. 16399 16400 16401Examples 16402""""""""" 16403 16404.. code-block:: llvm 16405 16406 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16407 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16408 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5) 16409 16410 ; The result in the following could be rounded up to 1 or down to 0.5 16411 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16412 16413 16414'``llvm.udiv.fix.*``' Intrinsics 16415^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16416 16417Syntax 16418""""""" 16419 16420This is an overloaded intrinsic. You can use ``llvm.udiv.fix`` 16421on any integer bit width or vectors of integers. 16422 16423:: 16424 16425 declare i16 @llvm.udiv.fix.i16(i16 %a, i16 %b, i32 %scale) 16426 declare i32 @llvm.udiv.fix.i32(i32 %a, i32 %b, i32 %scale) 16427 declare i64 @llvm.udiv.fix.i64(i64 %a, i64 %b, i32 %scale) 16428 declare <4 x i32> @llvm.udiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16429 16430Overview 16431""""""""" 16432 16433The '``llvm.udiv.fix``' family of intrinsic functions perform unsigned 16434fixed point division on 2 arguments of the same scale. 16435 16436Arguments 16437"""""""""" 16438 16439The arguments (%a and %b) and the result may be of integer types of any bit 16440width, but they must have the same bit width. The arguments may also work with 16441int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16442values that will undergo unsigned fixed point division. The argument 16443``%scale`` represents the scale of both operands, and must be a constant 16444integer. 16445 16446Semantics: 16447"""""""""" 16448 16449This operation performs fixed point division on the 2 arguments of a 16450specified scale. The result will also be returned in the same scale specified 16451in the third argument. 16452 16453If the result value cannot be precisely represented in the given scale, the 16454value is rounded up or down to the closest representable value. The rounding 16455direction is unspecified. 16456 16457It is undefined behavior if the result value does not fit within the range of 16458the fixed point type, or if the second argument is zero. 16459 16460 16461Examples 16462""""""""" 16463 16464.. code-block:: llvm 16465 16466 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16467 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16468 %res = call i4 @llvm.udiv.fix.i4(i4 1, i4 -8, i32 4) ; %res = 2 (0.0625 / 0.5 = 0.125) 16469 16470 ; The result in the following could be rounded up to 1 or down to 0.5 16471 %res = call i4 @llvm.udiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16472 16473 16474'``llvm.sdiv.fix.sat.*``' Intrinsics 16475^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16476 16477Syntax 16478""""""" 16479 16480This is an overloaded intrinsic. You can use ``llvm.sdiv.fix.sat`` 16481on any integer bit width or vectors of integers. 16482 16483:: 16484 16485 declare i16 @llvm.sdiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16486 declare i32 @llvm.sdiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16487 declare i64 @llvm.sdiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16488 declare <4 x i32> @llvm.sdiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16489 16490Overview 16491""""""""" 16492 16493The '``llvm.sdiv.fix.sat``' family of intrinsic functions perform signed 16494fixed point saturating division on 2 arguments of the same scale. 16495 16496Arguments 16497"""""""""" 16498 16499The arguments (%a and %b) and the result may be of integer types of any bit 16500width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16501values that will undergo signed fixed point division. The argument 16502``%scale`` represents the scale of both operands, and must be a constant 16503integer. 16504 16505Semantics: 16506"""""""""" 16507 16508This operation performs fixed point division on the 2 arguments of a 16509specified scale. The result will also be returned in the same scale specified 16510in the third argument. 16511 16512If the result value cannot be precisely represented in the given scale, the 16513value is rounded up or down to the closest representable value. The rounding 16514direction is unspecified. 16515 16516The maximum value this operation can clamp to is the largest signed value 16517representable by the bit width of the first 2 arguments. The minimum value is the 16518smallest signed value representable by this bit width. 16519 16520It is undefined behavior if the second argument is zero. 16521 16522 16523Examples 16524""""""""" 16525 16526.. code-block:: llvm 16527 16528 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16529 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16530 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5) 16531 16532 ; The result in the following could be rounded up to 1 or down to 0.5 16533 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16534 16535 ; Saturation 16536 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -8, i4 -1, i32 0) ; %res = 7 (-8 / -1 = 8 => 7) 16537 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 4, i4 2, i32 2) ; %res = 7 (1 / 0.5 = 2 => 1.75) 16538 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -4, i4 1, i32 2) ; %res = -8 (-1 / 0.25 = -4 => -2) 16539 16540 16541'``llvm.udiv.fix.sat.*``' Intrinsics 16542^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16543 16544Syntax 16545""""""" 16546 16547This is an overloaded intrinsic. You can use ``llvm.udiv.fix.sat`` 16548on any integer bit width or vectors of integers. 16549 16550:: 16551 16552 declare i16 @llvm.udiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16553 declare i32 @llvm.udiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16554 declare i64 @llvm.udiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16555 declare <4 x i32> @llvm.udiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16556 16557Overview 16558""""""""" 16559 16560The '``llvm.udiv.fix.sat``' family of intrinsic functions perform unsigned 16561fixed point saturating division on 2 arguments of the same scale. 16562 16563Arguments 16564"""""""""" 16565 16566The arguments (%a and %b) and the result may be of integer types of any bit 16567width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16568values that will undergo unsigned fixed point division. The argument 16569``%scale`` represents the scale of both operands, and must be a constant 16570integer. 16571 16572Semantics: 16573"""""""""" 16574 16575This operation performs fixed point division on the 2 arguments of a 16576specified scale. The result will also be returned in the same scale specified 16577in the third argument. 16578 16579If the result value cannot be precisely represented in the given scale, the 16580value is rounded up or down to the closest representable value. The rounding 16581direction is unspecified. 16582 16583The maximum value this operation can clamp to is the largest unsigned value 16584representable by the bit width of the first 2 arguments. The minimum value is the 16585smallest unsigned value representable by this bit width (zero). 16586 16587It is undefined behavior if the second argument is zero. 16588 16589Examples 16590""""""""" 16591 16592.. code-block:: llvm 16593 16594 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16595 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16596 16597 ; The result in the following could be rounded down to 0.5 or up to 1 16598 %res = call i4 @llvm.udiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 1 (or 2) (1.5 / 2 = 0.75) 16599 16600 ; Saturation 16601 %res = call i4 @llvm.udiv.fix.sat.i4(i4 8, i4 2, i32 2) ; %res = 15 (2 / 0.5 = 4 => 3.75) 16602 16603 16604Specialised Arithmetic Intrinsics 16605--------------------------------- 16606 16607.. _i_intr_llvm_canonicalize: 16608 16609'``llvm.canonicalize.*``' Intrinsic 16610^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16611 16612Syntax: 16613""""""" 16614 16615:: 16616 16617 declare float @llvm.canonicalize.f32(float %a) 16618 declare double @llvm.canonicalize.f64(double %b) 16619 16620Overview: 16621""""""""" 16622 16623The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical 16624encoding of a floating-point number. This canonicalization is useful for 16625implementing certain numeric primitives such as frexp. The canonical encoding is 16626defined by IEEE-754-2008 to be: 16627 16628:: 16629 16630 2.1.8 canonical encoding: The preferred encoding of a floating-point 16631 representation in a format. Applied to declets, significands of finite 16632 numbers, infinities, and NaNs, especially in decimal formats. 16633 16634This operation can also be considered equivalent to the IEEE-754-2008 16635conversion of a floating-point value to the same format. NaNs are handled 16636according to section 6.2. 16637 16638Examples of non-canonical encodings: 16639 16640- x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are 16641 converted to a canonical representation per hardware-specific protocol. 16642- Many normal decimal floating-point numbers have non-canonical alternative 16643 encodings. 16644- Some machines, like GPUs or ARMv7 NEON, do not support subnormal values. 16645 These are treated as non-canonical encodings of zero and will be flushed to 16646 a zero of the same sign by this operation. 16647 16648Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with 16649default exception handling must signal an invalid exception, and produce a 16650quiet NaN result. 16651 16652This function should always be implementable as multiplication by 1.0, provided 16653that the compiler does not constant fold the operation. Likewise, division by 166541.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with 16655-0.0 is also sufficient provided that the rounding mode is not -Infinity. 16656 16657``@llvm.canonicalize`` must preserve the equality relation. That is: 16658 16659- ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)`` 16660- ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to 16661 to ``(x == y)`` 16662 16663Additionally, the sign of zero must be conserved: 16664``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0`` 16665 16666The payload bits of a NaN must be conserved, with two exceptions. 16667First, environments which use only a single canonical representation of NaN 16668must perform said canonicalization. Second, SNaNs must be quieted per the 16669usual methods. 16670 16671The canonicalization operation may be optimized away if: 16672 16673- The input is known to be canonical. For example, it was produced by a 16674 floating-point operation that is required by the standard to be canonical. 16675- The result is consumed only by (or fused with) other floating-point 16676 operations. That is, the bits of the floating-point value are not examined. 16677 16678'``llvm.fmuladd.*``' Intrinsic 16679^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16680 16681Syntax: 16682""""""" 16683 16684:: 16685 16686 declare float @llvm.fmuladd.f32(float %a, float %b, float %c) 16687 declare double @llvm.fmuladd.f64(double %a, double %b, double %c) 16688 16689Overview: 16690""""""""" 16691 16692The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add 16693expressions that can be fused if the code generator determines that (a) the 16694target instruction set has support for a fused operation, and (b) that the 16695fused operation is more efficient than the equivalent, separate pair of mul 16696and add instructions. 16697 16698Arguments: 16699"""""""""" 16700 16701The '``llvm.fmuladd.*``' intrinsics each take three arguments: two 16702multiplicands, a and b, and an addend c. 16703 16704Semantics: 16705"""""""""" 16706 16707The expression: 16708 16709:: 16710 16711 %0 = call float @llvm.fmuladd.f32(%a, %b, %c) 16712 16713is equivalent to the expression a \* b + c, except that it is unspecified 16714whether rounding will be performed between the multiplication and addition 16715steps. Fusion is not guaranteed, even if the target platform supports it. 16716If a fused multiply-add is required, the corresponding 16717:ref:`llvm.fma <int_fma>` intrinsic function should be used instead. 16718This never sets errno, just as '``llvm.fma.*``'. 16719 16720Examples: 16721""""""""" 16722 16723.. code-block:: llvm 16724 16725 %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c 16726 16727 16728Hardware-Loop Intrinsics 16729------------------------ 16730 16731LLVM support several intrinsics to mark a loop as a hardware-loop. They are 16732hints to the backend which are required to lower these intrinsics further to target 16733specific instructions, or revert the hardware-loop to a normal loop if target 16734specific restriction are not met and a hardware-loop can't be generated. 16735 16736These intrinsics may be modified in the future and are not intended to be used 16737outside the backend. Thus, front-end and mid-level optimizations should not be 16738generating these intrinsics. 16739 16740 16741'``llvm.set.loop.iterations.*``' Intrinsic 16742^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16743 16744Syntax: 16745""""""" 16746 16747This is an overloaded intrinsic. 16748 16749:: 16750 16751 declare void @llvm.set.loop.iterations.i32(i32) 16752 declare void @llvm.set.loop.iterations.i64(i64) 16753 16754Overview: 16755""""""""" 16756 16757The '``llvm.set.loop.iterations.*``' intrinsics are used to specify the 16758hardware-loop trip count. They are placed in the loop preheader basic block and 16759are marked as ``IntrNoDuplicate`` to avoid optimizers duplicating these 16760instructions. 16761 16762Arguments: 16763"""""""""" 16764 16765The integer operand is the loop trip count of the hardware-loop, and thus 16766not e.g. the loop back-edge taken count. 16767 16768Semantics: 16769"""""""""" 16770 16771The '``llvm.set.loop.iterations.*``' intrinsics do not perform any arithmetic 16772on their operand. It's a hint to the backend that can use this to set up the 16773hardware-loop count with a target specific instruction, usually a move of this 16774value to a special register or a hardware-loop instruction. 16775 16776 16777'``llvm.start.loop.iterations.*``' Intrinsic 16778^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16779 16780Syntax: 16781""""""" 16782 16783This is an overloaded intrinsic. 16784 16785:: 16786 16787 declare i32 @llvm.start.loop.iterations.i32(i32) 16788 declare i64 @llvm.start.loop.iterations.i64(i64) 16789 16790Overview: 16791""""""""" 16792 16793The '``llvm.start.loop.iterations.*``' intrinsics are similar to the 16794'``llvm.set.loop.iterations.*``' intrinsics, used to specify the 16795hardware-loop trip count but also produce a value identical to the input 16796that can be used as the input to the loop. They are placed in the loop 16797preheader basic block and the output is expected to be the input to the 16798phi for the induction variable of the loop, decremented by the 16799'``llvm.loop.decrement.reg.*``'. 16800 16801Arguments: 16802"""""""""" 16803 16804The integer operand is the loop trip count of the hardware-loop, and thus 16805not e.g. the loop back-edge taken count. 16806 16807Semantics: 16808"""""""""" 16809 16810The '``llvm.start.loop.iterations.*``' intrinsics do not perform any arithmetic 16811on their operand. It's a hint to the backend that can use this to set up the 16812hardware-loop count with a target specific instruction, usually a move of this 16813value to a special register or a hardware-loop instruction. 16814 16815'``llvm.test.set.loop.iterations.*``' Intrinsic 16816^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16817 16818Syntax: 16819""""""" 16820 16821This is an overloaded intrinsic. 16822 16823:: 16824 16825 declare i1 @llvm.test.set.loop.iterations.i32(i32) 16826 declare i1 @llvm.test.set.loop.iterations.i64(i64) 16827 16828Overview: 16829""""""""" 16830 16831The '``llvm.test.set.loop.iterations.*``' intrinsics are used to specify the 16832the loop trip count, and also test that the given count is not zero, allowing 16833it to control entry to a while-loop. They are placed in the loop preheader's 16834predecessor basic block, and are marked as ``IntrNoDuplicate`` to avoid 16835optimizers duplicating these instructions. 16836 16837Arguments: 16838"""""""""" 16839 16840The integer operand is the loop trip count of the hardware-loop, and thus 16841not e.g. the loop back-edge taken count. 16842 16843Semantics: 16844"""""""""" 16845 16846The '``llvm.test.set.loop.iterations.*``' intrinsics do not perform any 16847arithmetic on their operand. It's a hint to the backend that can use this to 16848set up the hardware-loop count with a target specific instruction, usually a 16849move of this value to a special register or a hardware-loop instruction. 16850The result is the conditional value of whether the given count is not zero. 16851 16852 16853'``llvm.test.start.loop.iterations.*``' Intrinsic 16854^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16855 16856Syntax: 16857""""""" 16858 16859This is an overloaded intrinsic. 16860 16861:: 16862 16863 declare {i32, i1} @llvm.test.start.loop.iterations.i32(i32) 16864 declare {i64, i1} @llvm.test.start.loop.iterations.i64(i64) 16865 16866Overview: 16867""""""""" 16868 16869The '``llvm.test.start.loop.iterations.*``' intrinsics are similar to the 16870'``llvm.test.set.loop.iterations.*``' and '``llvm.start.loop.iterations.*``' 16871intrinsics, used to specify the hardware-loop trip count, but also produce a 16872value identical to the input that can be used as the input to the loop. The 16873second i1 output controls entry to a while-loop. 16874 16875Arguments: 16876"""""""""" 16877 16878The integer operand is the loop trip count of the hardware-loop, and thus 16879not e.g. the loop back-edge taken count. 16880 16881Semantics: 16882"""""""""" 16883 16884The '``llvm.test.start.loop.iterations.*``' intrinsics do not perform any 16885arithmetic on their operand. It's a hint to the backend that can use this to 16886set up the hardware-loop count with a target specific instruction, usually a 16887move of this value to a special register or a hardware-loop instruction. 16888The result is a pair of the input and a conditional value of whether the 16889given count is not zero. 16890 16891 16892'``llvm.loop.decrement.reg.*``' Intrinsic 16893^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16894 16895Syntax: 16896""""""" 16897 16898This is an overloaded intrinsic. 16899 16900:: 16901 16902 declare i32 @llvm.loop.decrement.reg.i32(i32, i32) 16903 declare i64 @llvm.loop.decrement.reg.i64(i64, i64) 16904 16905Overview: 16906""""""""" 16907 16908The '``llvm.loop.decrement.reg.*``' intrinsics are used to lower the loop 16909iteration counter and return an updated value that will be used in the next 16910loop test check. 16911 16912Arguments: 16913"""""""""" 16914 16915Both arguments must have identical integer types. The first operand is the 16916loop iteration counter. The second operand is the maximum number of elements 16917processed in an iteration. 16918 16919Semantics: 16920"""""""""" 16921 16922The '``llvm.loop.decrement.reg.*``' intrinsics do an integer ``SUB`` of its 16923two operands, which is not allowed to wrap. They return the remaining number of 16924iterations still to be executed, and can be used together with a ``PHI``, 16925``ICMP`` and ``BR`` to control the number of loop iterations executed. Any 16926optimisations are allowed to treat it is a ``SUB``, and it is supported by 16927SCEV, so it's the backends responsibility to handle cases where it may be 16928optimised. These intrinsics are marked as ``IntrNoDuplicate`` to avoid 16929optimizers duplicating these instructions. 16930 16931 16932'``llvm.loop.decrement.*``' Intrinsic 16933^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16934 16935Syntax: 16936""""""" 16937 16938This is an overloaded intrinsic. 16939 16940:: 16941 16942 declare i1 @llvm.loop.decrement.i32(i32) 16943 declare i1 @llvm.loop.decrement.i64(i64) 16944 16945Overview: 16946""""""""" 16947 16948The HardwareLoops pass allows the loop decrement value to be specified with an 16949option. It defaults to a loop decrement value of 1, but it can be an unsigned 16950integer value provided by this option. The '``llvm.loop.decrement.*``' 16951intrinsics decrement the loop iteration counter with this value, and return a 16952false predicate if the loop should exit, and true otherwise. 16953This is emitted if the loop counter is not updated via a ``PHI`` node, which 16954can also be controlled with an option. 16955 16956Arguments: 16957"""""""""" 16958 16959The integer argument is the loop decrement value used to decrement the loop 16960iteration counter. 16961 16962Semantics: 16963"""""""""" 16964 16965The '``llvm.loop.decrement.*``' intrinsics do a ``SUB`` of the loop iteration 16966counter with the given loop decrement value, and return false if the loop 16967should exit, this ``SUB`` is not allowed to wrap. The result is a condition 16968that is used by the conditional branch controlling the loop. 16969 16970 16971Vector Reduction Intrinsics 16972--------------------------- 16973 16974Horizontal reductions of vectors can be expressed using the following 16975intrinsics. Each one takes a vector operand as an input and applies its 16976respective operation across all elements of the vector, returning a single 16977scalar result of the same element type. 16978 16979.. _int_vector_reduce_add: 16980 16981'``llvm.vector.reduce.add.*``' Intrinsic 16982^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16983 16984Syntax: 16985""""""" 16986 16987:: 16988 16989 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a) 16990 declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a) 16991 16992Overview: 16993""""""""" 16994 16995The '``llvm.vector.reduce.add.*``' intrinsics do an integer ``ADD`` 16996reduction of a vector, returning the result as a scalar. The return type matches 16997the element-type of the vector input. 16998 16999Arguments: 17000"""""""""" 17001The argument to this intrinsic must be a vector of integer values. 17002 17003.. _int_vector_reduce_fadd: 17004 17005'``llvm.vector.reduce.fadd.*``' Intrinsic 17006^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17007 17008Syntax: 17009""""""" 17010 17011:: 17012 17013 declare float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %a) 17014 declare double @llvm.vector.reduce.fadd.v2f64(double %start_value, <2 x double> %a) 17015 17016Overview: 17017""""""""" 17018 17019The '``llvm.vector.reduce.fadd.*``' intrinsics do a floating-point 17020``ADD`` reduction of a vector, returning the result as a scalar. The return type 17021matches the element-type of the vector input. 17022 17023If the intrinsic call has the 'reassoc' flag set, then the reduction will not 17024preserve the associativity of an equivalent scalarized counterpart. Otherwise 17025the reduction will be *sequential*, thus implying that the operation respects 17026the associativity of a scalarized reduction. That is, the reduction begins with 17027the start value and performs an fadd operation with consecutively increasing 17028vector element indices. See the following pseudocode: 17029 17030:: 17031 17032 float sequential_fadd(start_value, input_vector) 17033 result = start_value 17034 for i = 0 to length(input_vector) 17035 result = result + input_vector[i] 17036 return result 17037 17038 17039Arguments: 17040"""""""""" 17041The first argument to this intrinsic is a scalar start value for the reduction. 17042The type of the start value matches the element-type of the vector input. 17043The second argument must be a vector of floating-point values. 17044 17045To ignore the start value, negative zero (``-0.0``) can be used, as it is 17046the neutral value of floating point addition. 17047 17048Examples: 17049""""""""" 17050 17051:: 17052 17053 %unord = call reassoc float @llvm.vector.reduce.fadd.v4f32(float -0.0, <4 x float> %input) ; relaxed reduction 17054 %ord = call float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %input) ; sequential reduction 17055 17056 17057.. _int_vector_reduce_mul: 17058 17059'``llvm.vector.reduce.mul.*``' Intrinsic 17060^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17061 17062Syntax: 17063""""""" 17064 17065:: 17066 17067 declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %a) 17068 declare i64 @llvm.vector.reduce.mul.v2i64(<2 x i64> %a) 17069 17070Overview: 17071""""""""" 17072 17073The '``llvm.vector.reduce.mul.*``' intrinsics do an integer ``MUL`` 17074reduction of a vector, returning the result as a scalar. The return type matches 17075the element-type of the vector input. 17076 17077Arguments: 17078"""""""""" 17079The argument to this intrinsic must be a vector of integer values. 17080 17081.. _int_vector_reduce_fmul: 17082 17083'``llvm.vector.reduce.fmul.*``' Intrinsic 17084^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17085 17086Syntax: 17087""""""" 17088 17089:: 17090 17091 declare float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %a) 17092 declare double @llvm.vector.reduce.fmul.v2f64(double %start_value, <2 x double> %a) 17093 17094Overview: 17095""""""""" 17096 17097The '``llvm.vector.reduce.fmul.*``' intrinsics do a floating-point 17098``MUL`` reduction of a vector, returning the result as a scalar. The return type 17099matches the element-type of the vector input. 17100 17101If the intrinsic call has the 'reassoc' flag set, then the reduction will not 17102preserve the associativity of an equivalent scalarized counterpart. Otherwise 17103the reduction will be *sequential*, thus implying that the operation respects 17104the associativity of a scalarized reduction. That is, the reduction begins with 17105the start value and performs an fmul operation with consecutively increasing 17106vector element indices. See the following pseudocode: 17107 17108:: 17109 17110 float sequential_fmul(start_value, input_vector) 17111 result = start_value 17112 for i = 0 to length(input_vector) 17113 result = result * input_vector[i] 17114 return result 17115 17116 17117Arguments: 17118"""""""""" 17119The first argument to this intrinsic is a scalar start value for the reduction. 17120The type of the start value matches the element-type of the vector input. 17121The second argument must be a vector of floating-point values. 17122 17123To ignore the start value, one (``1.0``) can be used, as it is the neutral 17124value of floating point multiplication. 17125 17126Examples: 17127""""""""" 17128 17129:: 17130 17131 %unord = call reassoc float @llvm.vector.reduce.fmul.v4f32(float 1.0, <4 x float> %input) ; relaxed reduction 17132 %ord = call float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %input) ; sequential reduction 17133 17134.. _int_vector_reduce_and: 17135 17136'``llvm.vector.reduce.and.*``' Intrinsic 17137^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17138 17139Syntax: 17140""""""" 17141 17142:: 17143 17144 declare i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %a) 17145 17146Overview: 17147""""""""" 17148 17149The '``llvm.vector.reduce.and.*``' intrinsics do a bitwise ``AND`` 17150reduction of a vector, returning the result as a scalar. The return type matches 17151the element-type of the vector input. 17152 17153Arguments: 17154"""""""""" 17155The argument to this intrinsic must be a vector of integer values. 17156 17157.. _int_vector_reduce_or: 17158 17159'``llvm.vector.reduce.or.*``' Intrinsic 17160^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17161 17162Syntax: 17163""""""" 17164 17165:: 17166 17167 declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %a) 17168 17169Overview: 17170""""""""" 17171 17172The '``llvm.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction 17173of a vector, returning the result as a scalar. The return type matches the 17174element-type of the vector input. 17175 17176Arguments: 17177"""""""""" 17178The argument to this intrinsic must be a vector of integer values. 17179 17180.. _int_vector_reduce_xor: 17181 17182'``llvm.vector.reduce.xor.*``' Intrinsic 17183^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17184 17185Syntax: 17186""""""" 17187 17188:: 17189 17190 declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %a) 17191 17192Overview: 17193""""""""" 17194 17195The '``llvm.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR`` 17196reduction of a vector, returning the result as a scalar. The return type matches 17197the element-type of the vector input. 17198 17199Arguments: 17200"""""""""" 17201The argument to this intrinsic must be a vector of integer values. 17202 17203.. _int_vector_reduce_smax: 17204 17205'``llvm.vector.reduce.smax.*``' Intrinsic 17206^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17207 17208Syntax: 17209""""""" 17210 17211:: 17212 17213 declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %a) 17214 17215Overview: 17216""""""""" 17217 17218The '``llvm.vector.reduce.smax.*``' intrinsics do a signed integer 17219``MAX`` reduction of a vector, returning the result as a scalar. The return type 17220matches the element-type of the vector input. 17221 17222Arguments: 17223"""""""""" 17224The argument to this intrinsic must be a vector of integer values. 17225 17226.. _int_vector_reduce_smin: 17227 17228'``llvm.vector.reduce.smin.*``' Intrinsic 17229^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17230 17231Syntax: 17232""""""" 17233 17234:: 17235 17236 declare i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %a) 17237 17238Overview: 17239""""""""" 17240 17241The '``llvm.vector.reduce.smin.*``' intrinsics do a signed integer 17242``MIN`` reduction of a vector, returning the result as a scalar. The return type 17243matches the element-type of the vector input. 17244 17245Arguments: 17246"""""""""" 17247The argument to this intrinsic must be a vector of integer values. 17248 17249.. _int_vector_reduce_umax: 17250 17251'``llvm.vector.reduce.umax.*``' Intrinsic 17252^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17253 17254Syntax: 17255""""""" 17256 17257:: 17258 17259 declare i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %a) 17260 17261Overview: 17262""""""""" 17263 17264The '``llvm.vector.reduce.umax.*``' intrinsics do an unsigned 17265integer ``MAX`` reduction of a vector, returning the result as a scalar. The 17266return type matches the element-type of the vector input. 17267 17268Arguments: 17269"""""""""" 17270The argument to this intrinsic must be a vector of integer values. 17271 17272.. _int_vector_reduce_umin: 17273 17274'``llvm.vector.reduce.umin.*``' Intrinsic 17275^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17276 17277Syntax: 17278""""""" 17279 17280:: 17281 17282 declare i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %a) 17283 17284Overview: 17285""""""""" 17286 17287The '``llvm.vector.reduce.umin.*``' intrinsics do an unsigned 17288integer ``MIN`` reduction of a vector, returning the result as a scalar. The 17289return type matches the element-type of the vector input. 17290 17291Arguments: 17292"""""""""" 17293The argument to this intrinsic must be a vector of integer values. 17294 17295.. _int_vector_reduce_fmax: 17296 17297'``llvm.vector.reduce.fmax.*``' Intrinsic 17298^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17299 17300Syntax: 17301""""""" 17302 17303:: 17304 17305 declare float @llvm.vector.reduce.fmax.v4f32(<4 x float> %a) 17306 declare double @llvm.vector.reduce.fmax.v2f64(<2 x double> %a) 17307 17308Overview: 17309""""""""" 17310 17311The '``llvm.vector.reduce.fmax.*``' intrinsics do a floating-point 17312``MAX`` reduction of a vector, returning the result as a scalar. The return type 17313matches the element-type of the vector input. 17314 17315This instruction has the same comparison semantics as the '``llvm.maxnum.*``' 17316intrinsic. That is, the result will always be a number unless all elements of 17317the vector are NaN. For a vector with maximum element magnitude 0.0 and 17318containing both +0.0 and -0.0 elements, the sign of the result is unspecified. 17319 17320If the intrinsic call has the ``nnan`` fast-math flag, then the operation can 17321assume that NaNs are not present in the input vector. 17322 17323Arguments: 17324"""""""""" 17325The argument to this intrinsic must be a vector of floating-point values. 17326 17327.. _int_vector_reduce_fmin: 17328 17329'``llvm.vector.reduce.fmin.*``' Intrinsic 17330^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17331 17332Syntax: 17333""""""" 17334This is an overloaded intrinsic. 17335 17336:: 17337 17338 declare float @llvm.vector.reduce.fmin.v4f32(<4 x float> %a) 17339 declare double @llvm.vector.reduce.fmin.v2f64(<2 x double> %a) 17340 17341Overview: 17342""""""""" 17343 17344The '``llvm.vector.reduce.fmin.*``' intrinsics do a floating-point 17345``MIN`` reduction of a vector, returning the result as a scalar. The return type 17346matches the element-type of the vector input. 17347 17348This instruction has the same comparison semantics as the '``llvm.minnum.*``' 17349intrinsic. That is, the result will always be a number unless all elements of 17350the vector are NaN. For a vector with minimum element magnitude 0.0 and 17351containing both +0.0 and -0.0 elements, the sign of the result is unspecified. 17352 17353If the intrinsic call has the ``nnan`` fast-math flag, then the operation can 17354assume that NaNs are not present in the input vector. 17355 17356Arguments: 17357"""""""""" 17358The argument to this intrinsic must be a vector of floating-point values. 17359 17360'``llvm.vector.insert``' Intrinsic 17361^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17362 17363Syntax: 17364""""""" 17365This is an overloaded intrinsic. 17366 17367:: 17368 17369 ; Insert fixed type into scalable type 17370 declare <vscale x 4 x float> @llvm.vector.insert.nxv4f32.v4f32(<vscale x 4 x float> %vec, <4 x float> %subvec, i64 <idx>) 17371 declare <vscale x 2 x double> @llvm.vector.insert.nxv2f64.v2f64(<vscale x 2 x double> %vec, <2 x double> %subvec, i64 <idx>) 17372 17373 ; Insert scalable type into scalable type 17374 declare <vscale x 4 x float> @llvm.vector.insert.nxv4f64.nxv2f64(<vscale x 4 x float> %vec, <vscale x 2 x float> %subvec, i64 <idx>) 17375 17376 ; Insert fixed type into fixed type 17377 declare <4 x double> @llvm.vector.insert.v4f64.v2f64(<4 x double> %vec, <2 x double> %subvec, i64 <idx>) 17378 17379Overview: 17380""""""""" 17381 17382The '``llvm.vector.insert.*``' intrinsics insert a vector into another vector 17383starting from a given index. The return type matches the type of the vector we 17384insert into. Conceptually, this can be used to build a scalable vector out of 17385non-scalable vectors, however this intrinsic can also be used on purely fixed 17386types. 17387 17388Scalable vectors can only be inserted into other scalable vectors. 17389 17390Arguments: 17391"""""""""" 17392 17393The ``vec`` is the vector which ``subvec`` will be inserted into. 17394The ``subvec`` is the vector that will be inserted. 17395 17396``idx`` represents the starting element number at which ``subvec`` will be 17397inserted. ``idx`` must be a constant multiple of ``subvec``'s known minimum 17398vector length. If ``subvec`` is a scalable vector, ``idx`` is first scaled by 17399the runtime scaling factor of ``subvec``. The elements of ``vec`` starting at 17400``idx`` are overwritten with ``subvec``. Elements ``idx`` through (``idx`` + 17401num_elements(``subvec``) - 1) must be valid ``vec`` indices. If this condition 17402cannot be determined statically but is false at runtime, then the result vector 17403is a :ref:`poison value <poisonvalues>`. 17404 17405 17406'``llvm.vector.extract``' Intrinsic 17407^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17408 17409Syntax: 17410""""""" 17411This is an overloaded intrinsic. 17412 17413:: 17414 17415 ; Extract fixed type from scalable type 17416 declare <4 x float> @llvm.vector.extract.v4f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>) 17417 declare <2 x double> @llvm.vector.extract.v2f64.nxv2f64(<vscale x 2 x double> %vec, i64 <idx>) 17418 17419 ; Extract scalable type from scalable type 17420 declare <vscale x 2 x float> @llvm.vector.extract.nxv2f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>) 17421 17422 ; Extract fixed type from fixed type 17423 declare <2 x double> @llvm.vector.extract.v2f64.v4f64(<4 x double> %vec, i64 <idx>) 17424 17425Overview: 17426""""""""" 17427 17428The '``llvm.vector.extract.*``' intrinsics extract a vector from within another 17429vector starting from a given index. The return type must be explicitly 17430specified. Conceptually, this can be used to decompose a scalable vector into 17431non-scalable parts, however this intrinsic can also be used on purely fixed 17432types. 17433 17434Scalable vectors can only be extracted from other scalable vectors. 17435 17436Arguments: 17437"""""""""" 17438 17439The ``vec`` is the vector from which we will extract a subvector. 17440 17441The ``idx`` specifies the starting element number within ``vec`` from which a 17442subvector is extracted. ``idx`` must be a constant multiple of the known-minimum 17443vector length of the result type. If the result type is a scalable vector, 17444``idx`` is first scaled by the result type's runtime scaling factor. Elements 17445``idx`` through (``idx`` + num_elements(result_type) - 1) must be valid vector 17446indices. If this condition cannot be determined statically but is false at 17447runtime, then the result vector is a :ref:`poison value <poisonvalues>`. The 17448``idx`` parameter must be a vector index constant type (for most targets this 17449will be an integer pointer type). 17450 17451'``llvm.experimental.vector.reverse``' Intrinsic 17452^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17453 17454Syntax: 17455""""""" 17456This is an overloaded intrinsic. 17457 17458:: 17459 17460 declare <2 x i8> @llvm.experimental.vector.reverse.v2i8(<2 x i8> %a) 17461 declare <vscale x 4 x i32> @llvm.experimental.vector.reverse.nxv4i32(<vscale x 4 x i32> %a) 17462 17463Overview: 17464""""""""" 17465 17466The '``llvm.experimental.vector.reverse.*``' intrinsics reverse a vector. 17467The intrinsic takes a single vector and returns a vector of matching type but 17468with the original lane order reversed. These intrinsics work for both fixed 17469and scalable vectors. While this intrinsic is marked as experimental the 17470recommended way to express reverse operations for fixed-width vectors is still 17471to use a shufflevector, as that may allow for more optimization opportunities. 17472 17473Arguments: 17474"""""""""" 17475 17476The argument to this intrinsic must be a vector. 17477 17478'``llvm.experimental.vector.splice``' Intrinsic 17479^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17480 17481Syntax: 17482""""""" 17483This is an overloaded intrinsic. 17484 17485:: 17486 17487 declare <2 x double> @llvm.experimental.vector.splice.v2f64(<2 x double> %vec1, <2 x double> %vec2, i32 %imm) 17488 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) 17489 17490Overview: 17491""""""""" 17492 17493The '``llvm.experimental.vector.splice.*``' intrinsics construct a vector by 17494concatenating elements from the first input vector with elements of the second 17495input vector, returning a vector of the same type as the input vectors. The 17496signed immediate, modulo the number of elements in the vector, is the index 17497into the first vector from which to extract the result value. This means 17498conceptually that for a positive immediate, a vector is extracted from 17499``concat(%vec1, %vec2)`` starting at index ``imm``, whereas for a negative 17500immediate, it extracts ``-imm`` trailing elements from the first vector, and 17501the remaining elements from ``%vec2``. 17502 17503These intrinsics work for both fixed and scalable vectors. While this intrinsic 17504is marked as experimental, the recommended way to express this operation for 17505fixed-width vectors is still to use a shufflevector, as that may allow for more 17506optimization opportunities. 17507 17508For example: 17509 17510.. code-block:: text 17511 17512 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, 1) ==> <B, C, D, E> ; index 17513 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, -3) ==> <B, C, D, E> ; trailing elements 17514 17515 17516Arguments: 17517"""""""""" 17518 17519The first two operands are vectors with the same type. The start index is imm 17520modulo the runtime number of elements in the source vector. For a fixed-width 17521vector <N x eltty>, imm is a signed integer constant in the range 17522-N <= imm < N. For a scalable vector <vscale x N x eltty>, imm is a signed 17523integer constant in the range -X <= imm < X where X=vscale_range_min * N. 17524 17525'``llvm.experimental.stepvector``' Intrinsic 17526^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17527 17528This is an overloaded intrinsic. You can use ``llvm.experimental.stepvector`` 17529to generate a vector whose lane values comprise the linear sequence 17530<0, 1, 2, ...>. It is primarily intended for scalable vectors. 17531 17532:: 17533 17534 declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32() 17535 declare <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16() 17536 17537The '``llvm.experimental.stepvector``' intrinsics are used to create vectors 17538of integers whose elements contain a linear sequence of values starting from 0 17539with a step of 1. This experimental intrinsic can only be used for vectors 17540with integer elements that are at least 8 bits in size. If the sequence value 17541exceeds the allowed limit for the element type then the result for that lane is 17542undefined. 17543 17544These intrinsics work for both fixed and scalable vectors. While this intrinsic 17545is marked as experimental, the recommended way to express this operation for 17546fixed-width vectors is still to generate a constant vector instead. 17547 17548 17549Arguments: 17550"""""""""" 17551 17552None. 17553 17554 17555Matrix Intrinsics 17556----------------- 17557 17558Operations on matrixes requiring shape information (like number of rows/columns 17559or the memory layout) can be expressed using the matrix intrinsics. These 17560intrinsics require matrix dimensions to be passed as immediate arguments, and 17561matrixes are passed and returned as vectors. This means that for a ``R`` x 17562``C`` matrix, element ``i`` of column ``j`` is at index ``j * R + i`` in the 17563corresponding vector, with indices starting at 0. Currently column-major layout 17564is assumed. The intrinsics support both integer and floating point matrixes. 17565 17566 17567'``llvm.matrix.transpose.*``' Intrinsic 17568^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17569 17570Syntax: 17571""""""" 17572This is an overloaded intrinsic. 17573 17574:: 17575 17576 declare vectorty @llvm.matrix.transpose.*(vectorty %In, i32 <Rows>, i32 <Cols>) 17577 17578Overview: 17579""""""""" 17580 17581The '``llvm.matrix.transpose.*``' intrinsics treat ``%In`` as a ``<Rows> x 17582<Cols>`` matrix and return the transposed matrix in the result vector. 17583 17584Arguments: 17585"""""""""" 17586 17587The first argument ``%In`` is a vector that corresponds to a ``<Rows> x 17588<Cols>`` matrix. Thus, arguments ``<Rows>`` and ``<Cols>`` correspond to the 17589number of rows and columns, respectively, and must be positive, constant 17590integers. The returned vector must have ``<Rows> * <Cols>`` elements, and have 17591the same float or integer element type as ``%In``. 17592 17593'``llvm.matrix.multiply.*``' Intrinsic 17594^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17595 17596Syntax: 17597""""""" 17598This is an overloaded intrinsic. 17599 17600:: 17601 17602 declare vectorty @llvm.matrix.multiply.*(vectorty %A, vectorty %B, i32 <OuterRows>, i32 <Inner>, i32 <OuterColumns>) 17603 17604Overview: 17605""""""""" 17606 17607The '``llvm.matrix.multiply.*``' intrinsics treat ``%A`` as a ``<OuterRows> x 17608<Inner>`` matrix, ``%B`` as a ``<Inner> x <OuterColumns>`` matrix, and 17609multiplies them. The result matrix is returned in the result vector. 17610 17611Arguments: 17612"""""""""" 17613 17614The first vector argument ``%A`` corresponds to a matrix with ``<OuterRows> * 17615<Inner>`` elements, and the second argument ``%B`` to a matrix with 17616``<Inner> * <OuterColumns>`` elements. Arguments ``<OuterRows>``, 17617``<Inner>`` and ``<OuterColumns>`` must be positive, constant integers. The 17618returned vector must have ``<OuterRows> * <OuterColumns>`` elements. 17619Vectors ``%A``, ``%B``, and the returned vector all have the same float or 17620integer element type. 17621 17622 17623'``llvm.matrix.column.major.load.*``' Intrinsic 17624^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17625 17626Syntax: 17627""""""" 17628This is an overloaded intrinsic. 17629 17630:: 17631 17632 declare vectorty @llvm.matrix.column.major.load.*( 17633 ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>) 17634 17635Overview: 17636""""""""" 17637 17638The '``llvm.matrix.column.major.load.*``' intrinsics load a ``<Rows> x <Cols>`` 17639matrix using a stride of ``%Stride`` to compute the start address of the 17640different columns. The offset is computed using ``%Stride``'s bitwidth. This 17641allows for convenient loading of sub matrixes. If ``<IsVolatile>`` is true, the 17642intrinsic is considered a :ref:`volatile memory access <volatile>`. The result 17643matrix is returned in the result vector. If the ``%Ptr`` argument is known to 17644be aligned to some boundary, this can be specified as an attribute on the 17645argument. 17646 17647Arguments: 17648"""""""""" 17649 17650The first argument ``%Ptr`` is a pointer type to the returned vector type, and 17651corresponds to the start address to load from. The second argument ``%Stride`` 17652is a positive, constant integer with ``%Stride >= <Rows>``. ``%Stride`` is used 17653to compute the column memory addresses. I.e., for a column ``C``, its start 17654memory addresses is calculated with ``%Ptr + C * %Stride``. The third Argument 17655``<IsVolatile>`` is a boolean value. The fourth and fifth arguments, 17656``<Rows>`` and ``<Cols>``, correspond to the number of rows and columns, 17657respectively, and must be positive, constant integers. The returned vector must 17658have ``<Rows> * <Cols>`` elements. 17659 17660The :ref:`align <attr_align>` parameter attribute can be provided for the 17661``%Ptr`` arguments. 17662 17663 17664'``llvm.matrix.column.major.store.*``' Intrinsic 17665^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17666 17667Syntax: 17668""""""" 17669 17670:: 17671 17672 declare void @llvm.matrix.column.major.store.*( 17673 vectorty %In, ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>) 17674 17675Overview: 17676""""""""" 17677 17678The '``llvm.matrix.column.major.store.*``' intrinsics store the ``<Rows> x 17679<Cols>`` matrix in ``%In`` to memory using a stride of ``%Stride`` between 17680columns. The offset is computed using ``%Stride``'s bitwidth. If 17681``<IsVolatile>`` is true, the intrinsic is considered a 17682:ref:`volatile memory access <volatile>`. 17683 17684If the ``%Ptr`` argument is known to be aligned to some boundary, this can be 17685specified as an attribute on the argument. 17686 17687Arguments: 17688"""""""""" 17689 17690The first argument ``%In`` is a vector that corresponds to a ``<Rows> x 17691<Cols>`` matrix to be stored to memory. The second argument ``%Ptr`` is a 17692pointer to the vector type of ``%In``, and is the start address of the matrix 17693in memory. The third argument ``%Stride`` is a positive, constant integer with 17694``%Stride >= <Rows>``. ``%Stride`` is used to compute the column memory 17695addresses. I.e., for a column ``C``, its start memory addresses is calculated 17696with ``%Ptr + C * %Stride``. The fourth argument ``<IsVolatile>`` is a boolean 17697value. The arguments ``<Rows>`` and ``<Cols>`` correspond to the number of rows 17698and columns, respectively, and must be positive, constant integers. 17699 17700The :ref:`align <attr_align>` parameter attribute can be provided 17701for the ``%Ptr`` arguments. 17702 17703 17704Half Precision Floating-Point Intrinsics 17705---------------------------------------- 17706 17707For most target platforms, half precision floating-point is a 17708storage-only format. This means that it is a dense encoding (in memory) 17709but does not support computation in the format. 17710 17711This means that code must first load the half-precision floating-point 17712value as an i16, then convert it to float with 17713:ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can 17714then be performed on the float value (including extending to double 17715etc). To store the value back to memory, it is first converted to float 17716if needed, then converted to i16 with 17717:ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an 17718i16 value. 17719 17720.. _int_convert_to_fp16: 17721 17722'``llvm.convert.to.fp16``' Intrinsic 17723^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17724 17725Syntax: 17726""""""" 17727 17728:: 17729 17730 declare i16 @llvm.convert.to.fp16.f32(float %a) 17731 declare i16 @llvm.convert.to.fp16.f64(double %a) 17732 17733Overview: 17734""""""""" 17735 17736The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 17737conventional floating-point type to half precision floating-point format. 17738 17739Arguments: 17740"""""""""" 17741 17742The intrinsic function contains single argument - the value to be 17743converted. 17744 17745Semantics: 17746"""""""""" 17747 17748The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 17749conventional floating-point format to half precision floating-point format. The 17750return value is an ``i16`` which contains the converted number. 17751 17752Examples: 17753""""""""" 17754 17755.. code-block:: llvm 17756 17757 %res = call i16 @llvm.convert.to.fp16.f32(float %a) 17758 store i16 %res, i16* @x, align 2 17759 17760.. _int_convert_from_fp16: 17761 17762'``llvm.convert.from.fp16``' Intrinsic 17763^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17764 17765Syntax: 17766""""""" 17767 17768:: 17769 17770 declare float @llvm.convert.from.fp16.f32(i16 %a) 17771 declare double @llvm.convert.from.fp16.f64(i16 %a) 17772 17773Overview: 17774""""""""" 17775 17776The '``llvm.convert.from.fp16``' intrinsic function performs a 17777conversion from half precision floating-point format to single precision 17778floating-point format. 17779 17780Arguments: 17781"""""""""" 17782 17783The intrinsic function contains single argument - the value to be 17784converted. 17785 17786Semantics: 17787"""""""""" 17788 17789The '``llvm.convert.from.fp16``' intrinsic function performs a 17790conversion from half single precision floating-point format to single 17791precision floating-point format. The input half-float value is 17792represented by an ``i16`` value. 17793 17794Examples: 17795""""""""" 17796 17797.. code-block:: llvm 17798 17799 %a = load i16, i16* @x, align 2 17800 %res = call float @llvm.convert.from.fp16(i16 %a) 17801 17802Saturating floating-point to integer conversions 17803------------------------------------------------ 17804 17805The ``fptoui`` and ``fptosi`` instructions return a 17806:ref:`poison value <poisonvalues>` if the rounded-towards-zero value is not 17807representable by the result type. These intrinsics provide an alternative 17808conversion, which will saturate towards the smallest and largest representable 17809integer values instead. 17810 17811'``llvm.fptoui.sat.*``' Intrinsic 17812^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17813 17814Syntax: 17815""""""" 17816 17817This is an overloaded intrinsic. You can use ``llvm.fptoui.sat`` on any 17818floating-point argument type and any integer result type, or vectors thereof. 17819Not all targets may support all types, however. 17820 17821:: 17822 17823 declare i32 @llvm.fptoui.sat.i32.f32(float %f) 17824 declare i19 @llvm.fptoui.sat.i19.f64(double %f) 17825 declare <4 x i100> @llvm.fptoui.sat.v4i100.v4f128(<4 x fp128> %f) 17826 17827Overview: 17828""""""""" 17829 17830This intrinsic converts the argument into an unsigned integer using saturating 17831semantics. 17832 17833Arguments: 17834"""""""""" 17835 17836The argument may be any floating-point or vector of floating-point type. The 17837return value may be any integer or vector of integer type. The number of vector 17838elements in argument and return must be the same. 17839 17840Semantics: 17841"""""""""" 17842 17843The conversion to integer is performed subject to the following rules: 17844 17845- If the argument is any NaN, zero is returned. 17846- If the argument is smaller than zero (this includes negative infinity), 17847 zero is returned. 17848- If the argument is larger than the largest representable unsigned integer of 17849 the result type (this includes positive infinity), the largest representable 17850 unsigned integer is returned. 17851- Otherwise, the result of rounding the argument towards zero is returned. 17852 17853Example: 17854"""""""" 17855 17856.. code-block:: text 17857 17858 %a = call i8 @llvm.fptoui.sat.i8.f32(float 123.9) ; yields i8: 123 17859 %b = call i8 @llvm.fptoui.sat.i8.f32(float -5.7) ; yields i8: 0 17860 %c = call i8 @llvm.fptoui.sat.i8.f32(float 377.0) ; yields i8: 255 17861 %d = call i8 @llvm.fptoui.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0 17862 17863'``llvm.fptosi.sat.*``' Intrinsic 17864^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17865 17866Syntax: 17867""""""" 17868 17869This is an overloaded intrinsic. You can use ``llvm.fptosi.sat`` on any 17870floating-point argument type and any integer result type, or vectors thereof. 17871Not all targets may support all types, however. 17872 17873:: 17874 17875 declare i32 @llvm.fptosi.sat.i32.f32(float %f) 17876 declare i19 @llvm.fptosi.sat.i19.f64(double %f) 17877 declare <4 x i100> @llvm.fptosi.sat.v4i100.v4f128(<4 x fp128> %f) 17878 17879Overview: 17880""""""""" 17881 17882This intrinsic converts the argument into a signed integer using saturating 17883semantics. 17884 17885Arguments: 17886"""""""""" 17887 17888The argument may be any floating-point or vector of floating-point type. The 17889return value may be any integer or vector of integer type. The number of vector 17890elements in argument and return must be the same. 17891 17892Semantics: 17893"""""""""" 17894 17895The conversion to integer is performed subject to the following rules: 17896 17897- If the argument is any NaN, zero is returned. 17898- If the argument is smaller than the smallest representable signed integer of 17899 the result type (this includes negative infinity), the smallest 17900 representable signed integer is returned. 17901- If the argument is larger than the largest representable signed integer of 17902 the result type (this includes positive infinity), the largest representable 17903 signed integer is returned. 17904- Otherwise, the result of rounding the argument towards zero is returned. 17905 17906Example: 17907"""""""" 17908 17909.. code-block:: text 17910 17911 %a = call i8 @llvm.fptosi.sat.i8.f32(float 23.9) ; yields i8: 23 17912 %b = call i8 @llvm.fptosi.sat.i8.f32(float -130.8) ; yields i8: -128 17913 %c = call i8 @llvm.fptosi.sat.i8.f32(float 999.0) ; yields i8: 127 17914 %d = call i8 @llvm.fptosi.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0 17915 17916.. _dbg_intrinsics: 17917 17918Debugger Intrinsics 17919------------------- 17920 17921The LLVM debugger intrinsics (which all start with ``llvm.dbg.`` 17922prefix), are described in the `LLVM Source Level 17923Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_ 17924document. 17925 17926Exception Handling Intrinsics 17927----------------------------- 17928 17929The LLVM exception handling intrinsics (which all start with 17930``llvm.eh.`` prefix), are described in the `LLVM Exception 17931Handling <ExceptionHandling.html#format-common-intrinsics>`_ document. 17932 17933Pointer Authentication Intrinsics 17934--------------------------------- 17935 17936The LLVM pointer authentication intrinsics (which all start with 17937``llvm.ptrauth.`` prefix), are described in the `Pointer Authentication 17938<PointerAuth.html#intrinsics>`_ document. 17939 17940.. _int_trampoline: 17941 17942Trampoline Intrinsics 17943--------------------- 17944 17945These intrinsics make it possible to excise one parameter, marked with 17946the :ref:`nest <nest>` attribute, from a function. The result is a 17947callable function pointer lacking the nest parameter - the caller does 17948not need to provide a value for it. Instead, the value to use is stored 17949in advance in a "trampoline", a block of memory usually allocated on the 17950stack, which also contains code to splice the nest value into the 17951argument list. This is used to implement the GCC nested function address 17952extension. 17953 17954For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)`` 17955then the resulting function pointer has signature ``i32 (i32, i32)*``. 17956It can be created as follows: 17957 17958.. code-block:: llvm 17959 17960 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86 17961 %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0 17962 call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval) 17963 %p = call i8* @llvm.adjust.trampoline(i8* %tramp1) 17964 %fp = bitcast i8* %p to i32 (i32, i32)* 17965 17966The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to 17967``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``. 17968 17969.. _int_it: 17970 17971'``llvm.init.trampoline``' Intrinsic 17972^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17973 17974Syntax: 17975""""""" 17976 17977:: 17978 17979 declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>) 17980 17981Overview: 17982""""""""" 17983 17984This fills the memory pointed to by ``tramp`` with executable code, 17985turning it into a trampoline. 17986 17987Arguments: 17988"""""""""" 17989 17990The ``llvm.init.trampoline`` intrinsic takes three arguments, all 17991pointers. The ``tramp`` argument must point to a sufficiently large and 17992sufficiently aligned block of memory; this memory is written to by the 17993intrinsic. Note that the size and the alignment are target-specific - 17994LLVM currently provides no portable way of determining them, so a 17995front-end that generates this intrinsic needs to have some 17996target-specific knowledge. The ``func`` argument must hold a function 17997bitcast to an ``i8*``. 17998 17999Semantics: 18000"""""""""" 18001 18002The block of memory pointed to by ``tramp`` is filled with target 18003dependent code, turning it into a function. Then ``tramp`` needs to be 18004passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can 18005be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new 18006function's signature is the same as that of ``func`` with any arguments 18007marked with the ``nest`` attribute removed. At most one such ``nest`` 18008argument is allowed, and it must be of pointer type. Calling the new 18009function is equivalent to calling ``func`` with the same argument list, 18010but with ``nval`` used for the missing ``nest`` argument. If, after 18011calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is 18012modified, then the effect of any later call to the returned function 18013pointer is undefined. 18014 18015.. _int_at: 18016 18017'``llvm.adjust.trampoline``' Intrinsic 18018^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18019 18020Syntax: 18021""""""" 18022 18023:: 18024 18025 declare i8* @llvm.adjust.trampoline(i8* <tramp>) 18026 18027Overview: 18028""""""""" 18029 18030This performs any required machine-specific adjustment to the address of 18031a trampoline (passed as ``tramp``). 18032 18033Arguments: 18034"""""""""" 18035 18036``tramp`` must point to a block of memory which already has trampoline 18037code filled in by a previous call to 18038:ref:`llvm.init.trampoline <int_it>`. 18039 18040Semantics: 18041"""""""""" 18042 18043On some architectures the address of the code to be executed needs to be 18044different than the address where the trampoline is actually stored. This 18045intrinsic returns the executable address corresponding to ``tramp`` 18046after performing the required machine specific adjustments. The pointer 18047returned can then be :ref:`bitcast and executed <int_trampoline>`. 18048 18049 18050.. _int_vp: 18051 18052Vector Predication Intrinsics 18053----------------------------- 18054VP intrinsics are intended for predicated SIMD/vector code. A typical VP 18055operation takes a vector mask and an explicit vector length parameter as in: 18056 18057:: 18058 18059 <W x T> llvm.vp.<opcode>.*(<W x T> %x, <W x T> %y, <W x i1> %mask, i32 %evl) 18060 18061The vector mask parameter (%mask) always has a vector of `i1` type, for example 18062`<32 x i1>`. The explicit vector length parameter always has the type `i32` and 18063is an unsigned integer value. The explicit vector length parameter (%evl) is in 18064the range: 18065 18066:: 18067 18068 0 <= %evl <= W, where W is the number of vector elements 18069 18070Note that for :ref:`scalable vector types <t_vector>` ``W`` is the runtime 18071length of the vector. 18072 18073The VP intrinsic has undefined behavior if ``%evl > W``. The explicit vector 18074length (%evl) creates a mask, %EVLmask, with all elements ``0 <= i < %evl`` set 18075to True, and all other lanes ``%evl <= i < W`` to False. A new mask %M is 18076calculated with an element-wise AND from %mask and %EVLmask: 18077 18078:: 18079 18080 M = %mask AND %EVLmask 18081 18082A vector operation ``<opcode>`` on vectors ``A`` and ``B`` calculates: 18083 18084:: 18085 18086 A <opcode> B = { A[i] <opcode> B[i] M[i] = True, and 18087 { undef otherwise 18088 18089Optimization Hint 18090^^^^^^^^^^^^^^^^^ 18091 18092Some targets, such as AVX512, do not support the %evl parameter in hardware. 18093The use of an effective %evl is discouraged for those targets. The function 18094``TargetTransformInfo::hasActiveVectorLength()`` returns true when the target 18095has native support for %evl. 18096 18097.. _int_vp_select: 18098 18099'``llvm.vp.select.*``' Intrinsics 18100^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18101 18102Syntax: 18103""""""" 18104This is an overloaded intrinsic. 18105 18106:: 18107 18108 declare <16 x i32> @llvm.vp.select.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <evl>) 18109 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>) 18110 18111Overview: 18112""""""""" 18113 18114The '``llvm.vp.select``' intrinsic is used to choose one value based on a 18115condition vector, without IR-level branching. 18116 18117Arguments: 18118"""""""""" 18119 18120The first operand is a vector of ``i1`` and indicates the condition. The 18121second operand is the value that is selected where the condition vector is 18122true. The third operand is the value that is selected where the condition 18123vector is false. The vectors must be of the same size. The fourth operand is 18124the explicit vector length. 18125 18126#. The optional ``fast-math flags`` marker indicates that the select has one or 18127 more :ref:`fast-math flags <fastmath>`. These are optimization hints to 18128 enable otherwise unsafe floating-point optimizations. Fast-math flags are 18129 only valid for selects that return a floating-point scalar or vector type, 18130 or an array (nested to any depth) of floating-point scalar or vector types. 18131 18132Semantics: 18133"""""""""" 18134 18135The intrinsic selects lanes from the second and third operand depending on a 18136condition vector. 18137 18138All result lanes at positions greater or equal than ``%evl`` are undefined. 18139For all lanes below ``%evl`` where the condition vector is true the lane is 18140taken from the second operand. Otherwise, the lane is taken from the third 18141operand. 18142 18143Example: 18144"""""""" 18145 18146.. code-block:: llvm 18147 18148 %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) 18149 18150 ;;; Expansion. 18151 ;; Any result is legal on lanes at and above %evl. 18152 %also.r = select <4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false 18153 18154 18155.. _int_vp_merge: 18156 18157'``llvm.vp.merge.*``' Intrinsics 18158^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18159 18160Syntax: 18161""""""" 18162This is an overloaded intrinsic. 18163 18164:: 18165 18166 declare <16 x i32> @llvm.vp.merge.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <pivot>) 18167 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>) 18168 18169Overview: 18170""""""""" 18171 18172The '``llvm.vp.merge``' intrinsic is used to choose one value based on a 18173condition vector and an index operand, without IR-level branching. 18174 18175Arguments: 18176"""""""""" 18177 18178The first operand is a vector of ``i1`` and indicates the condition. The 18179second operand is the value that is merged where the condition vector is true. 18180The third operand is the value that is selected where the condition vector is 18181false or the lane position is greater equal than the pivot. The fourth operand 18182is the pivot. 18183 18184#. The optional ``fast-math flags`` marker indicates that the merge has one or 18185 more :ref:`fast-math flags <fastmath>`. These are optimization hints to 18186 enable otherwise unsafe floating-point optimizations. Fast-math flags are 18187 only valid for merges that return a floating-point scalar or vector type, 18188 or an array (nested to any depth) of floating-point scalar or vector types. 18189 18190Semantics: 18191"""""""""" 18192 18193The intrinsic selects lanes from the second and third operand depending on a 18194condition vector and pivot value. 18195 18196For all lanes where the condition vector is true and the lane position is less 18197than ``%pivot`` the lane is taken from the second operand. Otherwise, the lane 18198is taken from the third operand. 18199 18200Example: 18201"""""""" 18202 18203.. code-block:: llvm 18204 18205 %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) 18206 18207 ;;; Expansion. 18208 ;; Lanes at and above %pivot are taken from %on_false 18209 %atfirst = insertelement <4 x i32> undef, i32 %pivot, i32 0 18210 %splat = shufflevector <4 x i32> %atfirst, <4 x i32> poison, <4 x i32> zeroinitializer 18211 %pivotmask = icmp ult <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32> %splat 18212 %mergemask = and <4 x i1> %cond, <4 x i1> %pivotmask 18213 %also.r = select <4 x i1> %mergemask, <4 x i32> %on_true, <4 x i32> %on_false 18214 18215 18216 18217.. _int_vp_add: 18218 18219'``llvm.vp.add.*``' Intrinsics 18220^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18221 18222Syntax: 18223""""""" 18224This is an overloaded intrinsic. 18225 18226:: 18227 18228 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>) 18229 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>) 18230 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>) 18231 18232Overview: 18233""""""""" 18234 18235Predicated integer addition of two vectors of integers. 18236 18237 18238Arguments: 18239"""""""""" 18240 18241The first two operands and the result have the same vector of integer type. The 18242third operand is the vector mask and has the same number of elements as the 18243result vector type. The fourth operand is the explicit vector length of the 18244operation. 18245 18246Semantics: 18247"""""""""" 18248 18249The '``llvm.vp.add``' intrinsic performs integer addition (:ref:`add <i_add>`) 18250of the first and second vector operand on each enabled lane. The result on 18251disabled lanes is undefined. 18252 18253Examples: 18254""""""""" 18255 18256.. code-block:: llvm 18257 18258 %r = call <4 x i32> @llvm.vp.add.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18259 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18260 18261 %t = add <4 x i32> %a, %b 18262 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18263 18264.. _int_vp_sub: 18265 18266'``llvm.vp.sub.*``' Intrinsics 18267^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18268 18269Syntax: 18270""""""" 18271This is an overloaded intrinsic. 18272 18273:: 18274 18275 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>) 18276 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>) 18277 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>) 18278 18279Overview: 18280""""""""" 18281 18282Predicated integer subtraction of two vectors of integers. 18283 18284 18285Arguments: 18286"""""""""" 18287 18288The first two operands and the result have the same vector of integer type. The 18289third operand is the vector mask and has the same number of elements as the 18290result vector type. The fourth operand is the explicit vector length of the 18291operation. 18292 18293Semantics: 18294"""""""""" 18295 18296The '``llvm.vp.sub``' intrinsic performs integer subtraction 18297(:ref:`sub <i_sub>`) of the first and second vector operand on each enabled 18298lane. The result on disabled lanes is undefined. 18299 18300Examples: 18301""""""""" 18302 18303.. code-block:: llvm 18304 18305 %r = call <4 x i32> @llvm.vp.sub.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18306 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18307 18308 %t = sub <4 x i32> %a, %b 18309 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18310 18311 18312 18313.. _int_vp_mul: 18314 18315'``llvm.vp.mul.*``' Intrinsics 18316^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18317 18318Syntax: 18319""""""" 18320This is an overloaded intrinsic. 18321 18322:: 18323 18324 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>) 18325 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>) 18326 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>) 18327 18328Overview: 18329""""""""" 18330 18331Predicated integer multiplication of two vectors of integers. 18332 18333 18334Arguments: 18335"""""""""" 18336 18337The first two operands and the result have the same vector of integer type. The 18338third operand is the vector mask and has the same number of elements as the 18339result vector type. The fourth operand is the explicit vector length of the 18340operation. 18341 18342Semantics: 18343"""""""""" 18344The '``llvm.vp.mul``' intrinsic performs integer multiplication 18345(:ref:`mul <i_mul>`) of the first and second vector operand on each enabled 18346lane. The result on disabled lanes is undefined. 18347 18348Examples: 18349""""""""" 18350 18351.. code-block:: llvm 18352 18353 %r = call <4 x i32> @llvm.vp.mul.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18354 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18355 18356 %t = mul <4 x i32> %a, %b 18357 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18358 18359 18360.. _int_vp_sdiv: 18361 18362'``llvm.vp.sdiv.*``' Intrinsics 18363^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18364 18365Syntax: 18366""""""" 18367This is an overloaded intrinsic. 18368 18369:: 18370 18371 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>) 18372 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>) 18373 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>) 18374 18375Overview: 18376""""""""" 18377 18378Predicated, signed division of two vectors of integers. 18379 18380 18381Arguments: 18382"""""""""" 18383 18384The first two operands and the result have the same vector of integer type. The 18385third operand is the vector mask and has the same number of elements as the 18386result vector type. The fourth operand is the explicit vector length of the 18387operation. 18388 18389Semantics: 18390"""""""""" 18391 18392The '``llvm.vp.sdiv``' intrinsic performs signed division (:ref:`sdiv <i_sdiv>`) 18393of the first and second vector operand on each enabled lane. The result on 18394disabled lanes is undefined. 18395 18396Examples: 18397""""""""" 18398 18399.. code-block:: llvm 18400 18401 %r = call <4 x i32> @llvm.vp.sdiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18402 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18403 18404 %t = sdiv <4 x i32> %a, %b 18405 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18406 18407 18408.. _int_vp_udiv: 18409 18410'``llvm.vp.udiv.*``' Intrinsics 18411^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18412 18413Syntax: 18414""""""" 18415This is an overloaded intrinsic. 18416 18417:: 18418 18419 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>) 18420 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>) 18421 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>) 18422 18423Overview: 18424""""""""" 18425 18426Predicated, unsigned division of two vectors of integers. 18427 18428 18429Arguments: 18430"""""""""" 18431 18432The 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. 18433 18434Semantics: 18435"""""""""" 18436 18437The '``llvm.vp.udiv``' intrinsic performs unsigned division 18438(:ref:`udiv <i_udiv>`) of the first and second vector operand on each enabled 18439lane. The result on disabled lanes is undefined. 18440 18441Examples: 18442""""""""" 18443 18444.. code-block:: llvm 18445 18446 %r = call <4 x i32> @llvm.vp.udiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18447 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18448 18449 %t = udiv <4 x i32> %a, %b 18450 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18451 18452 18453 18454.. _int_vp_srem: 18455 18456'``llvm.vp.srem.*``' Intrinsics 18457^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18458 18459Syntax: 18460""""""" 18461This is an overloaded intrinsic. 18462 18463:: 18464 18465 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>) 18466 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>) 18467 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>) 18468 18469Overview: 18470""""""""" 18471 18472Predicated computations of the signed remainder of two integer vectors. 18473 18474 18475Arguments: 18476"""""""""" 18477 18478The first two operands and the result have the same vector of integer type. The 18479third operand is the vector mask and has the same number of elements as the 18480result vector type. The fourth operand is the explicit vector length of the 18481operation. 18482 18483Semantics: 18484"""""""""" 18485 18486The '``llvm.vp.srem``' intrinsic computes the remainder of the signed division 18487(:ref:`srem <i_srem>`) of the first and second vector operand on each enabled 18488lane. The result on disabled lanes is undefined. 18489 18490Examples: 18491""""""""" 18492 18493.. code-block:: llvm 18494 18495 %r = call <4 x i32> @llvm.vp.srem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18496 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18497 18498 %t = srem <4 x i32> %a, %b 18499 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18500 18501 18502 18503.. _int_vp_urem: 18504 18505'``llvm.vp.urem.*``' Intrinsics 18506^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18507 18508Syntax: 18509""""""" 18510This is an overloaded intrinsic. 18511 18512:: 18513 18514 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>) 18515 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>) 18516 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>) 18517 18518Overview: 18519""""""""" 18520 18521Predicated computation of the unsigned remainder of two integer vectors. 18522 18523 18524Arguments: 18525"""""""""" 18526 18527The first two operands and the result have the same vector of integer type. The 18528third operand is the vector mask and has the same number of elements as the 18529result vector type. The fourth operand is the explicit vector length of the 18530operation. 18531 18532Semantics: 18533"""""""""" 18534 18535The '``llvm.vp.urem``' intrinsic computes the remainder of the unsigned division 18536(:ref:`urem <i_urem>`) of the first and second vector operand on each enabled 18537lane. The result on disabled lanes is undefined. 18538 18539Examples: 18540""""""""" 18541 18542.. code-block:: llvm 18543 18544 %r = call <4 x i32> @llvm.vp.urem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18545 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18546 18547 %t = urem <4 x i32> %a, %b 18548 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18549 18550 18551.. _int_vp_ashr: 18552 18553'``llvm.vp.ashr.*``' Intrinsics 18554^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18555 18556Syntax: 18557""""""" 18558This is an overloaded intrinsic. 18559 18560:: 18561 18562 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>) 18563 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>) 18564 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>) 18565 18566Overview: 18567""""""""" 18568 18569Vector-predicated arithmetic right-shift. 18570 18571 18572Arguments: 18573"""""""""" 18574 18575The first two operands and the result have the same vector of integer type. The 18576third operand is the vector mask and has the same number of elements as the 18577result vector type. The fourth operand is the explicit vector length of the 18578operation. 18579 18580Semantics: 18581"""""""""" 18582 18583The '``llvm.vp.ashr``' intrinsic computes the arithmetic right shift 18584(:ref:`ashr <i_ashr>`) of the first operand by the second operand on each 18585enabled lane. The result on disabled lanes is undefined. 18586 18587Examples: 18588""""""""" 18589 18590.. code-block:: llvm 18591 18592 %r = call <4 x i32> @llvm.vp.ashr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18593 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18594 18595 %t = ashr <4 x i32> %a, %b 18596 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18597 18598 18599.. _int_vp_lshr: 18600 18601 18602'``llvm.vp.lshr.*``' Intrinsics 18603^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18604 18605Syntax: 18606""""""" 18607This is an overloaded intrinsic. 18608 18609:: 18610 18611 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>) 18612 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>) 18613 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>) 18614 18615Overview: 18616""""""""" 18617 18618Vector-predicated logical right-shift. 18619 18620 18621Arguments: 18622"""""""""" 18623 18624The first two operands and the result have the same vector of integer type. The 18625third operand is the vector mask and has the same number of elements as the 18626result vector type. The fourth operand is the explicit vector length of the 18627operation. 18628 18629Semantics: 18630"""""""""" 18631 18632The '``llvm.vp.lshr``' intrinsic computes the logical right shift 18633(:ref:`lshr <i_lshr>`) of the first operand by the second operand on each 18634enabled lane. The result on disabled lanes is undefined. 18635 18636Examples: 18637""""""""" 18638 18639.. code-block:: llvm 18640 18641 %r = call <4 x i32> @llvm.vp.lshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18642 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18643 18644 %t = lshr <4 x i32> %a, %b 18645 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18646 18647 18648.. _int_vp_shl: 18649 18650'``llvm.vp.shl.*``' Intrinsics 18651^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18652 18653Syntax: 18654""""""" 18655This is an overloaded intrinsic. 18656 18657:: 18658 18659 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>) 18660 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>) 18661 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>) 18662 18663Overview: 18664""""""""" 18665 18666Vector-predicated left shift. 18667 18668 18669Arguments: 18670"""""""""" 18671 18672The first two operands and the result have the same vector of integer type. The 18673third operand is the vector mask and has the same number of elements as the 18674result vector type. The fourth operand is the explicit vector length of the 18675operation. 18676 18677Semantics: 18678"""""""""" 18679 18680The '``llvm.vp.shl``' intrinsic computes the left shift (:ref:`shl <i_shl>`) of 18681the first operand by the second operand on each enabled lane. The result on 18682disabled lanes is undefined. 18683 18684Examples: 18685""""""""" 18686 18687.. code-block:: llvm 18688 18689 %r = call <4 x i32> @llvm.vp.shl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18690 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18691 18692 %t = shl <4 x i32> %a, %b 18693 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18694 18695 18696.. _int_vp_or: 18697 18698'``llvm.vp.or.*``' Intrinsics 18699^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18700 18701Syntax: 18702""""""" 18703This is an overloaded intrinsic. 18704 18705:: 18706 18707 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>) 18708 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>) 18709 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>) 18710 18711Overview: 18712""""""""" 18713 18714Vector-predicated or. 18715 18716 18717Arguments: 18718"""""""""" 18719 18720The first two operands and the result have the same vector of integer type. The 18721third operand is the vector mask and has the same number of elements as the 18722result vector type. The fourth operand is the explicit vector length of the 18723operation. 18724 18725Semantics: 18726"""""""""" 18727 18728The '``llvm.vp.or``' intrinsic performs a bitwise or (:ref:`or <i_or>`) of the 18729first two operands on each enabled lane. The result on disabled lanes is 18730undefined. 18731 18732Examples: 18733""""""""" 18734 18735.. code-block:: llvm 18736 18737 %r = call <4 x i32> @llvm.vp.or.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18738 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18739 18740 %t = or <4 x i32> %a, %b 18741 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18742 18743 18744.. _int_vp_and: 18745 18746'``llvm.vp.and.*``' Intrinsics 18747^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18748 18749Syntax: 18750""""""" 18751This is an overloaded intrinsic. 18752 18753:: 18754 18755 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>) 18756 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>) 18757 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>) 18758 18759Overview: 18760""""""""" 18761 18762Vector-predicated and. 18763 18764 18765Arguments: 18766"""""""""" 18767 18768The first two operands and the result have the same vector of integer type. The 18769third operand is the vector mask and has the same number of elements as the 18770result vector type. The fourth operand is the explicit vector length of the 18771operation. 18772 18773Semantics: 18774"""""""""" 18775 18776The '``llvm.vp.and``' intrinsic performs a bitwise and (:ref:`and <i_or>`) of 18777the first two operands on each enabled lane. The result on disabled lanes is 18778undefined. 18779 18780Examples: 18781""""""""" 18782 18783.. code-block:: llvm 18784 18785 %r = call <4 x i32> @llvm.vp.and.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18786 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18787 18788 %t = and <4 x i32> %a, %b 18789 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18790 18791 18792.. _int_vp_xor: 18793 18794'``llvm.vp.xor.*``' Intrinsics 18795^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18796 18797Syntax: 18798""""""" 18799This is an overloaded intrinsic. 18800 18801:: 18802 18803 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>) 18804 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>) 18805 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>) 18806 18807Overview: 18808""""""""" 18809 18810Vector-predicated, bitwise xor. 18811 18812 18813Arguments: 18814"""""""""" 18815 18816The first two operands and the result have the same vector of integer type. The 18817third operand is the vector mask and has the same number of elements as the 18818result vector type. The fourth operand is the explicit vector length of the 18819operation. 18820 18821Semantics: 18822"""""""""" 18823 18824The '``llvm.vp.xor``' intrinsic performs a bitwise xor (:ref:`xor <i_xor>`) of 18825the first two operands on each enabled lane. 18826The result on disabled lanes is undefined. 18827 18828Examples: 18829""""""""" 18830 18831.. code-block:: llvm 18832 18833 %r = call <4 x i32> @llvm.vp.xor.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18834 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18835 18836 %t = xor <4 x i32> %a, %b 18837 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18838 18839 18840.. _int_vp_fadd: 18841 18842'``llvm.vp.fadd.*``' Intrinsics 18843^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18844 18845Syntax: 18846""""""" 18847This is an overloaded intrinsic. 18848 18849:: 18850 18851 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>) 18852 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>) 18853 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>) 18854 18855Overview: 18856""""""""" 18857 18858Predicated floating-point addition of two vectors of floating-point values. 18859 18860 18861Arguments: 18862"""""""""" 18863 18864The first two operands and the result have the same vector of floating-point type. The 18865third operand is the vector mask and has the same number of elements as the 18866result vector type. The fourth operand is the explicit vector length of the 18867operation. 18868 18869Semantics: 18870"""""""""" 18871 18872The '``llvm.vp.fadd``' intrinsic performs floating-point addition (:ref:`fadd <i_fadd>`) 18873of the first and second vector operand on each enabled lane. The result on 18874disabled lanes is undefined. The operation is performed in the default 18875floating-point environment. 18876 18877Examples: 18878""""""""" 18879 18880.. code-block:: llvm 18881 18882 %r = call <4 x float> @llvm.vp.fadd.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18883 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18884 18885 %t = fadd <4 x float> %a, %b 18886 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18887 18888 18889.. _int_vp_fsub: 18890 18891'``llvm.vp.fsub.*``' Intrinsics 18892^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18893 18894Syntax: 18895""""""" 18896This is an overloaded intrinsic. 18897 18898:: 18899 18900 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>) 18901 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>) 18902 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>) 18903 18904Overview: 18905""""""""" 18906 18907Predicated floating-point subtraction of two vectors of floating-point values. 18908 18909 18910Arguments: 18911"""""""""" 18912 18913The first two operands and the result have the same vector of floating-point type. The 18914third operand is the vector mask and has the same number of elements as the 18915result vector type. The fourth operand is the explicit vector length of the 18916operation. 18917 18918Semantics: 18919"""""""""" 18920 18921The '``llvm.vp.fsub``' intrinsic performs floating-point subtraction (:ref:`fsub <i_fsub>`) 18922of the first and second vector operand on each enabled lane. The result on 18923disabled lanes is undefined. The operation is performed in the default 18924floating-point environment. 18925 18926Examples: 18927""""""""" 18928 18929.. code-block:: llvm 18930 18931 %r = call <4 x float> @llvm.vp.fsub.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18932 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18933 18934 %t = fsub <4 x float> %a, %b 18935 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18936 18937 18938.. _int_vp_fmul: 18939 18940'``llvm.vp.fmul.*``' Intrinsics 18941^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18942 18943Syntax: 18944""""""" 18945This is an overloaded intrinsic. 18946 18947:: 18948 18949 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>) 18950 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>) 18951 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>) 18952 18953Overview: 18954""""""""" 18955 18956Predicated floating-point multiplication of two vectors of floating-point values. 18957 18958 18959Arguments: 18960"""""""""" 18961 18962The first two operands and the result have the same vector of floating-point type. The 18963third operand is the vector mask and has the same number of elements as the 18964result vector type. The fourth operand is the explicit vector length of the 18965operation. 18966 18967Semantics: 18968"""""""""" 18969 18970The '``llvm.vp.fmul``' intrinsic performs floating-point multiplication (:ref:`fmul <i_fmul>`) 18971of the first and second vector operand on each enabled lane. The result on 18972disabled lanes is undefined. The operation is performed in the default 18973floating-point environment. 18974 18975Examples: 18976""""""""" 18977 18978.. code-block:: llvm 18979 18980 %r = call <4 x float> @llvm.vp.fmul.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18981 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18982 18983 %t = fmul <4 x float> %a, %b 18984 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18985 18986 18987.. _int_vp_fdiv: 18988 18989'``llvm.vp.fdiv.*``' Intrinsics 18990^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18991 18992Syntax: 18993""""""" 18994This is an overloaded intrinsic. 18995 18996:: 18997 18998 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>) 18999 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>) 19000 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>) 19001 19002Overview: 19003""""""""" 19004 19005Predicated floating-point division of two vectors of floating-point values. 19006 19007 19008Arguments: 19009"""""""""" 19010 19011The first two operands and the result have the same vector of floating-point type. The 19012third operand is the vector mask and has the same number of elements as the 19013result vector type. The fourth operand is the explicit vector length of the 19014operation. 19015 19016Semantics: 19017"""""""""" 19018 19019The '``llvm.vp.fdiv``' intrinsic performs floating-point division (:ref:`fdiv <i_fdiv>`) 19020of the first and second vector operand on each enabled lane. The result on 19021disabled lanes is undefined. The operation is performed in the default 19022floating-point environment. 19023 19024Examples: 19025""""""""" 19026 19027.. code-block:: llvm 19028 19029 %r = call <4 x float> @llvm.vp.fdiv.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 19030 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19031 19032 %t = fdiv <4 x float> %a, %b 19033 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 19034 19035 19036.. _int_vp_frem: 19037 19038'``llvm.vp.frem.*``' Intrinsics 19039^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19040 19041Syntax: 19042""""""" 19043This is an overloaded intrinsic. 19044 19045:: 19046 19047 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>) 19048 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>) 19049 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>) 19050 19051Overview: 19052""""""""" 19053 19054Predicated floating-point remainder of two vectors of floating-point values. 19055 19056 19057Arguments: 19058"""""""""" 19059 19060The first two operands and the result have the same vector of floating-point type. The 19061third operand is the vector mask and has the same number of elements as the 19062result vector type. The fourth operand is the explicit vector length of the 19063operation. 19064 19065Semantics: 19066"""""""""" 19067 19068The '``llvm.vp.frem``' intrinsic performs floating-point remainder (:ref:`frem <i_frem>`) 19069of the first and second vector operand on each enabled lane. The result on 19070disabled lanes is undefined. The operation is performed in the default 19071floating-point environment. 19072 19073Examples: 19074""""""""" 19075 19076.. code-block:: llvm 19077 19078 %r = call <4 x float> @llvm.vp.frem.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 19079 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19080 19081 %t = frem <4 x float> %a, %b 19082 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 19083 19084 19085.. _int_vp_fneg: 19086 19087'``llvm.vp.fneg.*``' Intrinsics 19088^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19089 19090Syntax: 19091""""""" 19092This is an overloaded intrinsic. 19093 19094:: 19095 19096 declare <16 x float> @llvm.vp.fneg.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 19097 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>) 19098 declare <256 x double> @llvm.vp.fneg.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 19099 19100Overview: 19101""""""""" 19102 19103Predicated floating-point negation of a vector of floating-point values. 19104 19105 19106Arguments: 19107"""""""""" 19108 19109The first operand and the result have the same vector of floating-point type. 19110The second operand is the vector mask and has the same number of elements as the 19111result vector type. The third operand is the explicit vector length of the 19112operation. 19113 19114Semantics: 19115"""""""""" 19116 19117The '``llvm.vp.fneg``' intrinsic performs floating-point negation (:ref:`fneg <i_fneg>`) 19118of the first vector operand on each enabled lane. The result on disabled lanes 19119is undefined. 19120 19121Examples: 19122""""""""" 19123 19124.. code-block:: llvm 19125 19126 %r = call <4 x float> @llvm.vp.fneg.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 19127 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19128 19129 %t = fneg <4 x float> %a 19130 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 19131 19132 19133.. _int_vp_fma: 19134 19135'``llvm.vp.fma.*``' Intrinsics 19136^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19137 19138Syntax: 19139""""""" 19140This is an overloaded intrinsic. 19141 19142:: 19143 19144 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>) 19145 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>) 19146 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>) 19147 19148Overview: 19149""""""""" 19150 19151Predicated floating-point fused multiply-add of two vectors of floating-point values. 19152 19153 19154Arguments: 19155"""""""""" 19156 19157The first three operands and the result have the same vector of floating-point type. The 19158fourth operand is the vector mask and has the same number of elements as the 19159result vector type. The fifth operand is the explicit vector length of the 19160operation. 19161 19162Semantics: 19163"""""""""" 19164 19165The '``llvm.vp.fma``' intrinsic performs floating-point fused multiply-add (:ref:`llvm.fma <int_fma>`) 19166of the first, second, and third vector operand on each enabled lane. The result on 19167disabled lanes is undefined. The operation is performed in the default 19168floating-point environment. 19169 19170Examples: 19171""""""""" 19172 19173.. code-block:: llvm 19174 19175 %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) 19176 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19177 19178 %t = call <4 x float> @llvm.fma(<4 x float> %a, <4 x float> %b, <4 x float> %c) 19179 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 19180 19181 19182.. _int_vp_reduce_add: 19183 19184'``llvm.vp.reduce.add.*``' Intrinsics 19185^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19186 19187Syntax: 19188""""""" 19189This is an overloaded intrinsic. 19190 19191:: 19192 19193 declare i32 @llvm.vp.reduce.add.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19194 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>) 19195 19196Overview: 19197""""""""" 19198 19199Predicated integer ``ADD`` reduction of a vector and a scalar starting value, 19200returning the result as a scalar. 19201 19202Arguments: 19203"""""""""" 19204 19205The first operand is the start value of the reduction, which must be a scalar 19206integer type equal to the result type. The second operand is the vector on 19207which the reduction is performed and must be a vector of integer values whose 19208element type is the result/start type. The third operand is the vector mask and 19209is a vector of boolean values with the same number of elements as the vector 19210operand. The fourth operand is the explicit vector length of the operation. 19211 19212Semantics: 19213"""""""""" 19214 19215The '``llvm.vp.reduce.add``' intrinsic performs the integer ``ADD`` reduction 19216(:ref:`llvm.vector.reduce.add <int_vector_reduce_add>`) of the vector operand 19217``val`` on each enabled lane, adding it to the scalar ``start_value``. Disabled 19218lanes are treated as containing the neutral value ``0`` (i.e. having no effect 19219on the reduction operation). If the vector length is zero, the result is equal 19220to ``start_value``. 19221 19222To ignore the start value, the neutral value can be used. 19223 19224Examples: 19225""""""""" 19226 19227.. code-block:: llvm 19228 19229 %r = call i32 @llvm.vp.reduce.add.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19230 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19231 ; are treated as though %mask were false for those lanes. 19232 19233 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> zeroinitializer 19234 %reduction = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %masked.a) 19235 %also.r = add i32 %reduction, %start 19236 19237 19238.. _int_vp_reduce_fadd: 19239 19240'``llvm.vp.reduce.fadd.*``' Intrinsics 19241^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19242 19243Syntax: 19244""""""" 19245This is an overloaded intrinsic. 19246 19247:: 19248 19249 declare float @llvm.vp.reduce.fadd.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>) 19250 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>) 19251 19252Overview: 19253""""""""" 19254 19255Predicated floating-point ``ADD`` reduction of a vector and a scalar starting 19256value, returning the result as a scalar. 19257 19258Arguments: 19259"""""""""" 19260 19261The first operand is the start value of the reduction, which must be a scalar 19262floating-point type equal to the result type. The second operand is the vector 19263on which the reduction is performed and must be a vector of floating-point 19264values whose element type is the result/start type. The third operand is the 19265vector mask and is a vector of boolean values with the same number of elements 19266as the vector operand. The fourth operand is the explicit vector length of the 19267operation. 19268 19269Semantics: 19270"""""""""" 19271 19272The '``llvm.vp.reduce.fadd``' intrinsic performs the floating-point ``ADD`` 19273reduction (:ref:`llvm.vector.reduce.fadd <int_vector_reduce_fadd>`) of the 19274vector operand ``val`` on each enabled lane, adding it to the scalar 19275``start_value``. Disabled lanes are treated as containing the neutral value 19276``-0.0`` (i.e. having no effect on the reduction operation). If no lanes are 19277enabled, the resulting value will be equal to ``start_value``. 19278 19279To ignore the start value, the neutral value can be used. 19280 19281See the unpredicated version (:ref:`llvm.vector.reduce.fadd 19282<int_vector_reduce_fadd>`) for more detail on the semantics of the reduction. 19283 19284Examples: 19285""""""""" 19286 19287.. code-block:: llvm 19288 19289 %r = call float @llvm.vp.reduce.fadd.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl) 19290 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19291 ; are treated as though %mask were false for those lanes. 19292 19293 %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> 19294 %also.r = call float @llvm.vector.reduce.fadd.v4f32(float %start, <4 x float> %masked.a) 19295 19296 19297.. _int_vp_reduce_mul: 19298 19299'``llvm.vp.reduce.mul.*``' Intrinsics 19300^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19301 19302Syntax: 19303""""""" 19304This is an overloaded intrinsic. 19305 19306:: 19307 19308 declare i32 @llvm.vp.reduce.mul.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19309 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>) 19310 19311Overview: 19312""""""""" 19313 19314Predicated integer ``MUL`` reduction of a vector and a scalar starting value, 19315returning the result as a scalar. 19316 19317 19318Arguments: 19319"""""""""" 19320 19321The first operand is the start value of the reduction, which must be a scalar 19322integer type equal to the result type. The second operand is the vector on 19323which the reduction is performed and must be a vector of integer values whose 19324element type is the result/start type. The third operand is the vector mask and 19325is a vector of boolean values with the same number of elements as the vector 19326operand. The fourth operand is the explicit vector length of the operation. 19327 19328Semantics: 19329"""""""""" 19330 19331The '``llvm.vp.reduce.mul``' intrinsic performs the integer ``MUL`` reduction 19332(:ref:`llvm.vector.reduce.mul <int_vector_reduce_mul>`) of the vector operand ``val`` 19333on each enabled lane, multiplying it by the scalar ``start_value``. Disabled 19334lanes are treated as containing the neutral value ``1`` (i.e. having no effect 19335on the reduction operation). If the vector length is zero, the result is the 19336start value. 19337 19338To ignore the start value, the neutral value can be used. 19339 19340Examples: 19341""""""""" 19342 19343.. code-block:: llvm 19344 19345 %r = call i32 @llvm.vp.reduce.mul.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19346 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19347 ; are treated as though %mask were false for those lanes. 19348 19349 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 1, i32 1, i32 1, i32 1> 19350 %reduction = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %masked.a) 19351 %also.r = mul i32 %reduction, %start 19352 19353.. _int_vp_reduce_fmul: 19354 19355'``llvm.vp.reduce.fmul.*``' Intrinsics 19356^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19357 19358Syntax: 19359""""""" 19360This is an overloaded intrinsic. 19361 19362:: 19363 19364 declare float @llvm.vp.reduce.fmul.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>) 19365 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>) 19366 19367Overview: 19368""""""""" 19369 19370Predicated floating-point ``MUL`` reduction of a vector and a scalar starting 19371value, returning the result as a scalar. 19372 19373 19374Arguments: 19375"""""""""" 19376 19377The first operand is the start value of the reduction, which must be a scalar 19378floating-point type equal to the result type. The second operand is the vector 19379on which the reduction is performed and must be a vector of floating-point 19380values whose element type is the result/start type. The third operand is the 19381vector mask and is a vector of boolean values with the same number of elements 19382as the vector operand. The fourth operand is the explicit vector length of the 19383operation. 19384 19385Semantics: 19386"""""""""" 19387 19388The '``llvm.vp.reduce.fmul``' intrinsic performs the floating-point ``MUL`` 19389reduction (:ref:`llvm.vector.reduce.fmul <int_vector_reduce_fmul>`) of the 19390vector operand ``val`` on each enabled lane, multiplying it by the scalar 19391`start_value``. Disabled lanes are treated as containing the neutral value 19392``1.0`` (i.e. having no effect on the reduction operation). If no lanes are 19393enabled, the resulting value will be equal to the starting value. 19394 19395To ignore the start value, the neutral value can be used. 19396 19397See the unpredicated version (:ref:`llvm.vector.reduce.fmul 19398<int_vector_reduce_fmul>`) for more detail on the semantics. 19399 19400Examples: 19401""""""""" 19402 19403.. code-block:: llvm 19404 19405 %r = call float @llvm.vp.reduce.fmul.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl) 19406 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19407 ; are treated as though %mask were false for those lanes. 19408 19409 %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> 19410 %also.r = call float @llvm.vector.reduce.fmul.v4f32(float %start, <4 x float> %masked.a) 19411 19412 19413.. _int_vp_reduce_and: 19414 19415'``llvm.vp.reduce.and.*``' Intrinsics 19416^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19417 19418Syntax: 19419""""""" 19420This is an overloaded intrinsic. 19421 19422:: 19423 19424 declare i32 @llvm.vp.reduce.and.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19425 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>) 19426 19427Overview: 19428""""""""" 19429 19430Predicated integer ``AND`` reduction of a vector and a scalar starting value, 19431returning the result as a scalar. 19432 19433 19434Arguments: 19435"""""""""" 19436 19437The first operand is the start value of the reduction, which must be a scalar 19438integer type equal to the result type. The second operand is the vector on 19439which the reduction is performed and must be a vector of integer values whose 19440element type is the result/start type. The third operand is the vector mask and 19441is a vector of boolean values with the same number of elements as the vector 19442operand. The fourth operand is the explicit vector length of the operation. 19443 19444Semantics: 19445"""""""""" 19446 19447The '``llvm.vp.reduce.and``' intrinsic performs the integer ``AND`` reduction 19448(:ref:`llvm.vector.reduce.and <int_vector_reduce_and>`) of the vector operand 19449``val`` on each enabled lane, performing an '``and``' of that with with the 19450scalar ``start_value``. Disabled lanes are treated as containing the neutral 19451value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction 19452operation). If the vector length is zero, the result is the start value. 19453 19454To ignore the start value, the neutral value can be used. 19455 19456Examples: 19457""""""""" 19458 19459.. code-block:: llvm 19460 19461 %r = call i32 @llvm.vp.reduce.and.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19462 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19463 ; are treated as though %mask were false for those lanes. 19464 19465 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1> 19466 %reduction = call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %masked.a) 19467 %also.r = and i32 %reduction, %start 19468 19469 19470.. _int_vp_reduce_or: 19471 19472'``llvm.vp.reduce.or.*``' Intrinsics 19473^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19474 19475Syntax: 19476""""""" 19477This is an overloaded intrinsic. 19478 19479:: 19480 19481 declare i32 @llvm.vp.reduce.or.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19482 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>) 19483 19484Overview: 19485""""""""" 19486 19487Predicated integer ``OR`` reduction of a vector and a scalar starting value, 19488returning the result as a scalar. 19489 19490 19491Arguments: 19492"""""""""" 19493 19494The first operand is the start value of the reduction, which must be a scalar 19495integer type equal to the result type. The second operand is the vector on 19496which the reduction is performed and must be a vector of integer values whose 19497element type is the result/start type. The third operand is the vector mask and 19498is a vector of boolean values with the same number of elements as the vector 19499operand. The fourth operand is the explicit vector length of the operation. 19500 19501Semantics: 19502"""""""""" 19503 19504The '``llvm.vp.reduce.or``' intrinsic performs the integer ``OR`` reduction 19505(:ref:`llvm.vector.reduce.or <int_vector_reduce_or>`) of the vector operand 19506``val`` on each enabled lane, performing an '``or``' of that with the scalar 19507``start_value``. Disabled lanes are treated as containing the neutral value 19508``0`` (i.e. having no effect on the reduction operation). If the vector length 19509is zero, the result is the start value. 19510 19511To ignore the start value, the neutral value can be used. 19512 19513Examples: 19514""""""""" 19515 19516.. code-block:: llvm 19517 19518 %r = call i32 @llvm.vp.reduce.or.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19519 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19520 ; are treated as though %mask were false for those lanes. 19521 19522 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0> 19523 %reduction = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %masked.a) 19524 %also.r = or i32 %reduction, %start 19525 19526.. _int_vp_reduce_xor: 19527 19528'``llvm.vp.reduce.xor.*``' Intrinsics 19529^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19530 19531Syntax: 19532""""""" 19533This is an overloaded intrinsic. 19534 19535:: 19536 19537 declare i32 @llvm.vp.reduce.xor.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19538 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>) 19539 19540Overview: 19541""""""""" 19542 19543Predicated integer ``XOR`` reduction of a vector and a scalar starting value, 19544returning the result as a scalar. 19545 19546 19547Arguments: 19548"""""""""" 19549 19550The first operand is the start value of the reduction, which must be a scalar 19551integer type equal to the result type. The second operand is the vector on 19552which the reduction is performed and must be a vector of integer values whose 19553element type is the result/start type. The third operand is the vector mask and 19554is a vector of boolean values with the same number of elements as the vector 19555operand. The fourth operand is the explicit vector length of the operation. 19556 19557Semantics: 19558"""""""""" 19559 19560The '``llvm.vp.reduce.xor``' intrinsic performs the integer ``XOR`` reduction 19561(:ref:`llvm.vector.reduce.xor <int_vector_reduce_xor>`) of the vector operand 19562``val`` on each enabled lane, performing an '``xor``' of that with the scalar 19563``start_value``. Disabled lanes are treated as containing the neutral value 19564``0`` (i.e. having no effect on the reduction operation). If the vector length 19565is zero, the result is the start value. 19566 19567To ignore the start value, the neutral value can be used. 19568 19569Examples: 19570""""""""" 19571 19572.. code-block:: llvm 19573 19574 %r = call i32 @llvm.vp.reduce.xor.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19575 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19576 ; are treated as though %mask were false for those lanes. 19577 19578 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0> 19579 %reduction = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %masked.a) 19580 %also.r = xor i32 %reduction, %start 19581 19582 19583.. _int_vp_reduce_smax: 19584 19585'``llvm.vp.reduce.smax.*``' Intrinsics 19586^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19587 19588Syntax: 19589""""""" 19590This is an overloaded intrinsic. 19591 19592:: 19593 19594 declare i32 @llvm.vp.reduce.smax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19595 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>) 19596 19597Overview: 19598""""""""" 19599 19600Predicated signed-integer ``MAX`` reduction of a vector and a scalar starting 19601value, returning the result as a scalar. 19602 19603 19604Arguments: 19605"""""""""" 19606 19607The first operand is the start value of the reduction, which must be a scalar 19608integer type equal to the result type. The second operand is the vector on 19609which the reduction is performed and must be a vector of integer values whose 19610element type is the result/start type. The third operand is the vector mask and 19611is a vector of boolean values with the same number of elements as the vector 19612operand. The fourth operand is the explicit vector length of the operation. 19613 19614Semantics: 19615"""""""""" 19616 19617The '``llvm.vp.reduce.smax``' intrinsic performs the signed-integer ``MAX`` 19618reduction (:ref:`llvm.vector.reduce.smax <int_vector_reduce_smax>`) of the 19619vector operand ``val`` on each enabled lane, and taking the maximum of that and 19620the scalar ``start_value``. Disabled lanes are treated as containing the 19621neutral value ``INT_MIN`` (i.e. having no effect on the reduction operation). 19622If the vector length is zero, the result is the start value. 19623 19624To ignore the start value, the neutral value can be used. 19625 19626Examples: 19627""""""""" 19628 19629.. code-block:: llvm 19630 19631 %r = call i8 @llvm.vp.reduce.smax.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl) 19632 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19633 ; are treated as though %mask were false for those lanes. 19634 19635 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 -128, i8 -128, i8 -128, i8 -128> 19636 %reduction = call i8 @llvm.vector.reduce.smax.v4i8(<4 x i8> %masked.a) 19637 %also.r = call i8 @llvm.smax.i8(i8 %reduction, i8 %start) 19638 19639 19640.. _int_vp_reduce_smin: 19641 19642'``llvm.vp.reduce.smin.*``' Intrinsics 19643^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19644 19645Syntax: 19646""""""" 19647This is an overloaded intrinsic. 19648 19649:: 19650 19651 declare i32 @llvm.vp.reduce.smin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19652 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>) 19653 19654Overview: 19655""""""""" 19656 19657Predicated signed-integer ``MIN`` reduction of a vector and a scalar starting 19658value, returning the result as a scalar. 19659 19660 19661Arguments: 19662"""""""""" 19663 19664The first operand is the start value of the reduction, which must be a scalar 19665integer type equal to the result type. The second operand is the vector on 19666which the reduction is performed and must be a vector of integer values whose 19667element type is the result/start type. The third operand is the vector mask and 19668is a vector of boolean values with the same number of elements as the vector 19669operand. The fourth operand is the explicit vector length of the operation. 19670 19671Semantics: 19672"""""""""" 19673 19674The '``llvm.vp.reduce.smin``' intrinsic performs the signed-integer ``MIN`` 19675reduction (:ref:`llvm.vector.reduce.smin <int_vector_reduce_smin>`) of the 19676vector operand ``val`` on each enabled lane, and taking the minimum of that and 19677the scalar ``start_value``. Disabled lanes are treated as containing the 19678neutral value ``INT_MAX`` (i.e. having no effect on the reduction operation). 19679If the vector length is zero, the result is the start value. 19680 19681To ignore the start value, the neutral value can be used. 19682 19683Examples: 19684""""""""" 19685 19686.. code-block:: llvm 19687 19688 %r = call i8 @llvm.vp.reduce.smin.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl) 19689 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19690 ; are treated as though %mask were false for those lanes. 19691 19692 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 127, i8 127, i8 127, i8 127> 19693 %reduction = call i8 @llvm.vector.reduce.smin.v4i8(<4 x i8> %masked.a) 19694 %also.r = call i8 @llvm.smin.i8(i8 %reduction, i8 %start) 19695 19696 19697.. _int_vp_reduce_umax: 19698 19699'``llvm.vp.reduce.umax.*``' Intrinsics 19700^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19701 19702Syntax: 19703""""""" 19704This is an overloaded intrinsic. 19705 19706:: 19707 19708 declare i32 @llvm.vp.reduce.umax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19709 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>) 19710 19711Overview: 19712""""""""" 19713 19714Predicated unsigned-integer ``MAX`` reduction of a vector and a scalar starting 19715value, returning the result as a scalar. 19716 19717 19718Arguments: 19719"""""""""" 19720 19721The first operand is the start value of the reduction, which must be a scalar 19722integer type equal to the result type. The second operand is the vector on 19723which the reduction is performed and must be a vector of integer values whose 19724element type is the result/start type. The third operand is the vector mask and 19725is a vector of boolean values with the same number of elements as the vector 19726operand. The fourth operand is the explicit vector length of the operation. 19727 19728Semantics: 19729"""""""""" 19730 19731The '``llvm.vp.reduce.umax``' intrinsic performs the unsigned-integer ``MAX`` 19732reduction (:ref:`llvm.vector.reduce.umax <int_vector_reduce_umax>`) of the 19733vector operand ``val`` on each enabled lane, and taking the maximum of that and 19734the scalar ``start_value``. Disabled lanes are treated as containing the 19735neutral value ``0`` (i.e. having no effect on the reduction operation). If the 19736vector length is zero, the result is the start value. 19737 19738To ignore the start value, the neutral value can be used. 19739 19740Examples: 19741""""""""" 19742 19743.. code-block:: llvm 19744 19745 %r = call i32 @llvm.vp.reduce.umax.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19746 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19747 ; are treated as though %mask were false for those lanes. 19748 19749 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0> 19750 %reduction = call i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %masked.a) 19751 %also.r = call i32 @llvm.umax.i32(i32 %reduction, i32 %start) 19752 19753 19754.. _int_vp_reduce_umin: 19755 19756'``llvm.vp.reduce.umin.*``' Intrinsics 19757^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19758 19759Syntax: 19760""""""" 19761This is an overloaded intrinsic. 19762 19763:: 19764 19765 declare i32 @llvm.vp.reduce.umin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19766 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>) 19767 19768Overview: 19769""""""""" 19770 19771Predicated unsigned-integer ``MIN`` reduction of a vector and a scalar starting 19772value, returning the result as a scalar. 19773 19774 19775Arguments: 19776"""""""""" 19777 19778The first operand is the start value of the reduction, which must be a scalar 19779integer type equal to the result type. The second operand is the vector on 19780which the reduction is performed and must be a vector of integer values whose 19781element type is the result/start type. The third operand is the vector mask and 19782is a vector of boolean values with the same number of elements as the vector 19783operand. The fourth operand is the explicit vector length of the operation. 19784 19785Semantics: 19786"""""""""" 19787 19788The '``llvm.vp.reduce.umin``' intrinsic performs the unsigned-integer ``MIN`` 19789reduction (:ref:`llvm.vector.reduce.umin <int_vector_reduce_umin>`) of the 19790vector operand ``val`` on each enabled lane, taking the minimum of that and the 19791scalar ``start_value``. Disabled lanes are treated as containing the neutral 19792value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction 19793operation). If the vector length is zero, the result is the start value. 19794 19795To ignore the start value, the neutral value can be used. 19796 19797Examples: 19798""""""""" 19799 19800.. code-block:: llvm 19801 19802 %r = call i32 @llvm.vp.reduce.umin.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19803 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19804 ; are treated as though %mask were false for those lanes. 19805 19806 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1> 19807 %reduction = call i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %masked.a) 19808 %also.r = call i32 @llvm.umin.i32(i32 %reduction, i32 %start) 19809 19810 19811.. _int_vp_reduce_fmax: 19812 19813'``llvm.vp.reduce.fmax.*``' Intrinsics 19814^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19815 19816Syntax: 19817""""""" 19818This is an overloaded intrinsic. 19819 19820:: 19821 19822 declare float @llvm.vp.reduce.fmax.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>) 19823 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>) 19824 19825Overview: 19826""""""""" 19827 19828Predicated floating-point ``MAX`` reduction of a vector and a scalar starting 19829value, returning the result as a scalar. 19830 19831 19832Arguments: 19833"""""""""" 19834 19835The first operand is the start value of the reduction, which must be a scalar 19836floating-point type equal to the result type. The second operand is the vector 19837on which the reduction is performed and must be a vector of floating-point 19838values whose element type is the result/start type. The third operand is the 19839vector mask and is a vector of boolean values with the same number of elements 19840as the vector operand. The fourth operand is the explicit vector length of the 19841operation. 19842 19843Semantics: 19844"""""""""" 19845 19846The '``llvm.vp.reduce.fmax``' intrinsic performs the floating-point ``MAX`` 19847reduction (:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>`) of the 19848vector operand ``val`` on each enabled lane, taking the maximum of that and the 19849scalar ``start_value``. Disabled lanes are treated as containing the neutral 19850value (i.e. having no effect on the reduction operation). If the vector length 19851is zero, the result is the start value. 19852 19853The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no 19854flags are set, the neutral value is ``-QNAN``. If ``nnan`` and ``ninf`` are 19855both set, then the neutral value is the smallest floating-point value for the 19856result type. If only ``nnan`` is set then the neutral value is ``-Infinity``. 19857 19858This instruction has the same comparison semantics as the 19859:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>` intrinsic (and thus the 19860'``llvm.maxnum.*``' intrinsic). That is, the result will always be a number 19861unless all elements of the vector and the starting value are ``NaN``. For a 19862vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and 19863``-0.0`` elements, the sign of the result is unspecified. 19864 19865To ignore the start value, the neutral value can be used. 19866 19867Examples: 19868""""""""" 19869 19870.. code-block:: llvm 19871 19872 %r = call float @llvm.vp.reduce.fmax.v4f32(float %float, <4 x float> %a, <4 x i1> %mask, i32 %evl) 19873 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19874 ; are treated as though %mask were false for those lanes. 19875 19876 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN> 19877 %reduction = call float @llvm.vector.reduce.fmax.v4f32(<4 x float> %masked.a) 19878 %also.r = call float @llvm.maxnum.f32(float %reduction, float %start) 19879 19880 19881.. _int_vp_reduce_fmin: 19882 19883'``llvm.vp.reduce.fmin.*``' Intrinsics 19884^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19885 19886Syntax: 19887""""""" 19888This is an overloaded intrinsic. 19889 19890:: 19891 19892 declare float @llvm.vp.reduce.fmin.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>) 19893 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>) 19894 19895Overview: 19896""""""""" 19897 19898Predicated floating-point ``MIN`` reduction of a vector and a scalar starting 19899value, returning the result as a scalar. 19900 19901 19902Arguments: 19903"""""""""" 19904 19905The first operand is the start value of the reduction, which must be a scalar 19906floating-point type equal to the result type. The second operand is the vector 19907on which the reduction is performed and must be a vector of floating-point 19908values whose element type is the result/start type. The third operand is the 19909vector mask and is a vector of boolean values with the same number of elements 19910as the vector operand. The fourth operand is the explicit vector length of the 19911operation. 19912 19913Semantics: 19914"""""""""" 19915 19916The '``llvm.vp.reduce.fmin``' intrinsic performs the floating-point ``MIN`` 19917reduction (:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>`) of the 19918vector operand ``val`` on each enabled lane, taking the minimum of that and the 19919scalar ``start_value``. Disabled lanes are treated as containing the neutral 19920value (i.e. having no effect on the reduction operation). If the vector length 19921is zero, the result is the start value. 19922 19923The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no 19924flags are set, the neutral value is ``+QNAN``. If ``nnan`` and ``ninf`` are 19925both set, then the neutral value is the largest floating-point value for the 19926result type. If only ``nnan`` is set then the neutral value is ``+Infinity``. 19927 19928This instruction has the same comparison semantics as the 19929:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>` intrinsic (and thus the 19930'``llvm.minnum.*``' intrinsic). That is, the result will always be a number 19931unless all elements of the vector and the starting value are ``NaN``. For a 19932vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and 19933``-0.0`` elements, the sign of the result is unspecified. 19934 19935To ignore the start value, the neutral value can be used. 19936 19937Examples: 19938""""""""" 19939 19940.. code-block:: llvm 19941 19942 %r = call float @llvm.vp.reduce.fmin.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl) 19943 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19944 ; are treated as though %mask were false for those lanes. 19945 19946 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN> 19947 %reduction = call float @llvm.vector.reduce.fmin.v4f32(<4 x float> %masked.a) 19948 %also.r = call float @llvm.minnum.f32(float %reduction, float %start) 19949 19950 19951.. _int_get_active_lane_mask: 19952 19953'``llvm.get.active.lane.mask.*``' Intrinsics 19954^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19955 19956Syntax: 19957""""""" 19958This is an overloaded intrinsic. 19959 19960:: 19961 19962 declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %base, i32 %n) 19963 declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 %base, i64 %n) 19964 declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 %base, i64 %n) 19965 declare <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 %base, i64 %n) 19966 19967 19968Overview: 19969""""""""" 19970 19971Create a mask representing active and inactive vector lanes. 19972 19973 19974Arguments: 19975"""""""""" 19976 19977Both operands have the same scalar integer type. The result is a vector with 19978the i1 element type. 19979 19980Semantics: 19981"""""""""" 19982 19983The '``llvm.get.active.lane.mask.*``' intrinsics are semantically equivalent 19984to: 19985 19986:: 19987 19988 %m[i] = icmp ult (%base + i), %n 19989 19990where ``%m`` is a vector (mask) of active/inactive lanes with its elements 19991indexed by ``i``, and ``%base``, ``%n`` are the two arguments to 19992``llvm.get.active.lane.mask.*``, ``%icmp`` is an integer compare and ``ult`` 19993the unsigned less-than comparison operator. Overflow cannot occur in 19994``(%base + i)`` and its comparison against ``%n`` as it is performed in integer 19995numbers and not in machine numbers. If ``%n`` is ``0``, then the result is a 19996poison value. The above is equivalent to: 19997 19998:: 19999 20000 %m = @llvm.get.active.lane.mask(%base, %n) 20001 20002This can, for example, be emitted by the loop vectorizer in which case 20003``%base`` is the first element of the vector induction variable (VIV) and 20004``%n`` is the loop tripcount. Thus, these intrinsics perform an element-wise 20005less than comparison of VIV with the loop tripcount, producing a mask of 20006true/false values representing active/inactive vector lanes, except if the VIV 20007overflows in which case they return false in the lanes where the VIV overflows. 20008The arguments are scalar types to accommodate scalable vector types, for which 20009it is unknown what the type of the step vector needs to be that enumerate its 20010lanes without overflow. 20011 20012This mask ``%m`` can e.g. be used in masked load/store instructions. These 20013intrinsics provide a hint to the backend. I.e., for a vector loop, the 20014back-edge taken count of the original scalar loop is explicit as the second 20015argument. 20016 20017 20018Examples: 20019""""""""" 20020 20021.. code-block:: llvm 20022 20023 %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 %elem0, i64 429) 20024 %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) 20025 20026 20027.. _int_experimental_vp_splice: 20028 20029'``llvm.experimental.vp.splice``' Intrinsic 20030^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20031 20032Syntax: 20033""""""" 20034This is an overloaded intrinsic. 20035 20036:: 20037 20038 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) 20039 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) 20040 20041Overview: 20042""""""""" 20043 20044The '``llvm.experimental.vp.splice.*``' intrinsic is the vector length 20045predicated version of the '``llvm.experimental.vector.splice.*``' intrinsic. 20046 20047Arguments: 20048"""""""""" 20049 20050The result and the first two arguments ``vec1`` and ``vec2`` are vectors with 20051the same type. The third argument ``imm`` is an immediate signed integer that 20052indicates the offset index. The fourth argument ``mask`` is a vector mask and 20053has the same number of elements as the result. The last two arguments ``evl1`` 20054and ``evl2`` are unsigned integers indicating the explicit vector lengths of 20055``vec1`` and ``vec2`` respectively. ``imm``, ``evl1`` and ``evl2`` should 20056respect the following constraints: ``-evl1 <= imm < evl1``, ``0 <= evl1 <= VL`` 20057and ``0 <= evl2 <= VL``, where ``VL`` is the runtime vector factor. If these 20058constraints are not satisfied the intrinsic has undefined behaviour. 20059 20060Semantics: 20061"""""""""" 20062 20063Effectively, this intrinsic concatenates ``vec1[0..evl1-1]`` and 20064``vec2[0..evl2-1]`` and creates the result vector by selecting the elements in a 20065window of size ``evl2``, starting at index ``imm`` (for a positive immediate) of 20066the concatenated vector. Elements in the result vector beyond ``evl2`` are 20067``undef``. If ``imm`` is negative the starting index is ``evl1 + imm``. The result 20068vector of active vector length ``evl2`` contains ``evl1 - imm`` (``-imm`` for 20069negative ``imm``) elements from indices ``[imm..evl1 - 1]`` 20070(``[evl1 + imm..evl1 -1]`` for negative ``imm``) of ``vec1`` followed by the 20071first ``evl2 - (evl1 - imm)`` (``evl2 + imm`` for negative ``imm``) elements of 20072``vec2``. If ``evl1 - imm`` (``-imm``) >= ``evl2``, only the first ``evl2`` 20073elements are considered and the remaining are ``undef``. The lanes in the result 20074vector disabled by ``mask`` are ``undef``. 20075 20076Examples: 20077""""""""" 20078 20079.. code-block:: text 20080 20081 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, 1, 2, 3) ==> <B, E, F, undef> ; index 20082 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, -2, 3, 2) ==> <B, C, undef, undef> ; trailing elements 20083 20084 20085.. _int_vp_load: 20086 20087'``llvm.vp.load``' Intrinsic 20088^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20089 20090Syntax: 20091""""""" 20092This is an overloaded intrinsic. 20093 20094:: 20095 20096 declare <4 x float> @llvm.vp.load.v4f32.p0v4f32(<4 x float>* %ptr, <4 x i1> %mask, i32 %evl) 20097 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) 20098 declare <8 x float> @llvm.vp.load.v8f32.p1v8f32(<8 x float> addrspace(1)* %ptr, <8 x i1> %mask, i32 %evl) 20099 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) 20100 20101Overview: 20102""""""""" 20103 20104The '``llvm.vp.load.*``' intrinsic is the vector length predicated version of 20105the :ref:`llvm.masked.load <int_mload>` intrinsic. 20106 20107Arguments: 20108"""""""""" 20109 20110The first operand is the base pointer for the load. The second operand is a 20111vector of boolean values with the same number of elements as the return type. 20112The third is the explicit vector length of the operation. The return type and 20113underlying type of the base pointer are the same vector types. 20114 20115The :ref:`align <attr_align>` parameter attribute can be provided for the first 20116operand. 20117 20118Semantics: 20119"""""""""" 20120 20121The '``llvm.vp.load``' intrinsic reads a vector from memory in the same way as 20122the '``llvm.masked.load``' intrinsic, where the mask is taken from the 20123combination of the '``mask``' and '``evl``' operands in the usual VP way. 20124Certain '``llvm.masked.load``' operands do not have corresponding operands in 20125'``llvm.vp.load``': the '``passthru``' operand is implicitly ``undef``; the 20126'``alignment``' operand is taken as the ``align`` parameter attribute, if 20127provided. The default alignment is taken as the ABI alignment of the return 20128type as specified by the :ref:`datalayout string<langref_datalayout>`. 20129 20130Examples: 20131""""""""" 20132 20133.. code-block:: text 20134 20135 %r = call <8 x i8> @llvm.vp.load.v8i8.p0v8i8(<8 x i8>* align 2 %ptr, <8 x i1> %mask, i32 %evl) 20136 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20137 20138 %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) 20139 20140 20141.. _int_vp_store: 20142 20143'``llvm.vp.store``' Intrinsic 20144^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20145 20146Syntax: 20147""""""" 20148This is an overloaded intrinsic. 20149 20150:: 20151 20152 declare void @llvm.vp.store.v4f32.p0v4f32(<4 x float> %val, <4 x float>* %ptr, <4 x i1> %mask, i32 %evl) 20153 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) 20154 declare void @llvm.vp.store.v8f32.p1v8f32(<8 x float> %val, <8 x float> addrspace(1)* %ptr, <8 x i1> %mask, i32 %evl) 20155 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) 20156 20157Overview: 20158""""""""" 20159 20160The '``llvm.vp.store.*``' intrinsic is the vector length predicated version of 20161the :ref:`llvm.masked.store <int_mstore>` intrinsic. 20162 20163Arguments: 20164"""""""""" 20165 20166The first operand is the vector value to be written to memory. The second 20167operand is the base pointer for the store. It has the same underlying type as 20168the value operand. The third operand is a vector of boolean values with the 20169same number of elements as the return type. The fourth is the explicit vector 20170length of the operation. 20171 20172The :ref:`align <attr_align>` parameter attribute can be provided for the 20173second operand. 20174 20175Semantics: 20176"""""""""" 20177 20178The '``llvm.vp.store``' intrinsic reads a vector from memory in the same way as 20179the '``llvm.masked.store``' intrinsic, where the mask is taken from the 20180combination of the '``mask``' and '``evl``' operands in the usual VP way. The 20181alignment of the operation (corresponding to the '``alignment``' operand of 20182'``llvm.masked.store``') is specified by the ``align`` parameter attribute (see 20183above). If it is not provided then the ABI alignment of the type of the 20184'``value``' operand as specified by the :ref:`datalayout 20185string<langref_datalayout>` is used instead. 20186 20187Examples: 20188""""""""" 20189 20190.. code-block:: text 20191 20192 call void @llvm.vp.store.v8i8.p0v8i8(<8 x i8> %val, <8 x i8>* align 4 %ptr, <8 x i1> %mask, i32 %evl) 20193 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below. 20194 20195 call void @llvm.masked.store.v8i8.p0v8i8(<8 x i8> %val, <8 x i8>* %ptr, i32 4, <8 x i1> %mask) 20196 20197 20198.. _int_experimental_vp_strided_load: 20199 20200'``llvm.experimental.vp.strided.load``' Intrinsic 20201^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20202 20203Syntax: 20204""""""" 20205This is an overloaded intrinsic. 20206 20207:: 20208 20209 declare <4 x float> @llvm.experimental.vp.strided.load.v4f32.i64(float* %ptr, i64 %stride, <4 x i1> %mask, i32 %evl) 20210 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) 20211 20212Overview: 20213""""""""" 20214 20215The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, scalar values from 20216memory locations evenly spaced apart by '``stride``' number of bytes, starting from '``ptr``'. 20217 20218Arguments: 20219"""""""""" 20220 20221The first operand is the base pointer for the load. The second operand is the stride 20222value expressed in bytes. The third operand is a vector of boolean values 20223with the same number of elements as the return type. The fourth is the explicit 20224vector length of the operation. The base pointer underlying type matches the type of the scalar 20225elements of the return operand. 20226 20227The :ref:`align <attr_align>` parameter attribute can be provided for the first 20228operand. 20229 20230Semantics: 20231"""""""""" 20232 20233The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, multiple scalar 20234values from memory in the same way as the :ref:`llvm.vp.gather <int_vp_gather>` intrinsic, 20235where the vector of pointers is in the form: 20236 20237 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``, 20238 20239with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed 20240integer and all arithmetic occurring in the pointer type. 20241 20242Examples: 20243""""""""" 20244 20245.. code-block:: text 20246 20247 %r = call <8 x i64> @llvm.experimental.vp.strided.load.v8i64.i64(i64* %ptr, i64 %stride, <8 x i64> %mask, i32 %evl) 20248 ;; The operation can also be expressed like this: 20249 20250 %addr = bitcast i64* %ptr to i8* 20251 ;; Create a vector of pointers %addrs in the form: 20252 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...> 20253 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* > 20254 %also.r = call <8 x i64> @llvm.vp.gather.v8i64.v8p0i64(<8 x i64* > %ptrs, <8 x i64> %mask, i32 %evl) 20255 20256 20257.. _int_experimental_vp_strided_store: 20258 20259'``llvm.experimental.vp.strided.store``' Intrinsic 20260^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20261 20262Syntax: 20263""""""" 20264This is an overloaded intrinsic. 20265 20266:: 20267 20268 declare void @llvm.experimental.vp.strided.store.v4f32.i64(<4 x float> %val, float* %ptr, i64 %stride, <4 x i1> %mask, i32 %evl) 20269 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) 20270 20271Overview: 20272""""""""" 20273 20274The '``@llvm.experimental.vp.strided.store``' intrinsic stores the elements of 20275'``val``' into memory locations evenly spaced apart by '``stride``' number of 20276bytes, starting from '``ptr``'. 20277 20278Arguments: 20279"""""""""" 20280 20281The first operand is the vector value to be written to memory. The second 20282operand is the base pointer for the store. Its underlying type matches the 20283scalar element type of the value operand. The third operand is the stride value 20284expressed in bytes. The fourth operand is a vector of boolean values with the 20285same number of elements as the return type. The fifth is the explicit vector 20286length of the operation. 20287 20288The :ref:`align <attr_align>` parameter attribute can be provided for the 20289second operand. 20290 20291Semantics: 20292"""""""""" 20293 20294The '``llvm.experimental.vp.strided.store``' intrinsic stores the elements of 20295'``val``' in the same way as the :ref:`llvm.vp.scatter <int_vp_scatter>` intrinsic, 20296where the vector of pointers is in the form: 20297 20298 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``, 20299 20300with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed 20301integer and all arithmetic occurring in the pointer type. 20302 20303Examples: 20304""""""""" 20305 20306.. code-block:: text 20307 20308 call void @llvm.experimental.vp.strided.store.v8i64.i64(<8 x i64> %val, i64* %ptr, i64 %stride, <8 x i1> %mask, i32 %evl) 20309 ;; The operation can also be expressed like this: 20310 20311 %addr = bitcast i64* %ptr to i8* 20312 ;; Create a vector of pointers %addrs in the form: 20313 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...> 20314 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* > 20315 call void @llvm.vp.scatter.v8i64.v8p0i64(<8 x i64> %val, <8 x i64*> %ptrs, <8 x i1> %mask, i32 %evl) 20316 20317 20318.. _int_vp_gather: 20319 20320'``llvm.vp.gather``' Intrinsic 20321^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20322 20323Syntax: 20324""""""" 20325This is an overloaded intrinsic. 20326 20327:: 20328 20329 declare <4 x double> @llvm.vp.gather.v4f64.v4p0f64(<4 x double*> %ptrs, <4 x i1> %mask, i32 %evl) 20330 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) 20331 declare <2 x float> @llvm.vp.gather.v2f32.v2p2f32(<2 x float addrspace(2)*> %ptrs, <2 x i1> %mask, i32 %evl) 20332 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) 20333 20334Overview: 20335""""""""" 20336 20337The '``llvm.vp.gather.*``' intrinsic is the vector length predicated version of 20338the :ref:`llvm.masked.gather <int_mgather>` intrinsic. 20339 20340Arguments: 20341"""""""""" 20342 20343The first operand is a vector of pointers which holds all memory addresses to 20344read. The second operand is a vector of boolean values with the same number of 20345elements as the return type. The third is the explicit vector length of the 20346operation. The return type and underlying type of the vector of pointers are 20347the same vector types. 20348 20349The :ref:`align <attr_align>` parameter attribute can be provided for the first 20350operand. 20351 20352Semantics: 20353"""""""""" 20354 20355The '``llvm.vp.gather``' intrinsic reads multiple scalar values from memory in 20356the same way as the '``llvm.masked.gather``' intrinsic, where the mask is taken 20357from the combination of the '``mask``' and '``evl``' operands in the usual VP 20358way. Certain '``llvm.masked.gather``' operands do not have corresponding 20359operands in '``llvm.vp.gather``': the '``passthru``' operand is implicitly 20360``undef``; the '``alignment``' operand is taken as the ``align`` parameter, if 20361provided. The default alignment is taken as the ABI alignment of the source 20362addresses as specified by the :ref:`datalayout string<langref_datalayout>`. 20363 20364Examples: 20365""""""""" 20366 20367.. code-block:: text 20368 20369 %r = call <8 x i8> @llvm.vp.gather.v8i8.v8p0i8(<8 x i8*> align 8 %ptrs, <8 x i1> %mask, i32 %evl) 20370 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20371 20372 %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) 20373 20374 20375.. _int_vp_scatter: 20376 20377'``llvm.vp.scatter``' Intrinsic 20378^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20379 20380Syntax: 20381""""""" 20382This is an overloaded intrinsic. 20383 20384:: 20385 20386 declare void @llvm.vp.scatter.v4f64.v4p0f64(<4 x double> %val, <4 x double*> %ptrs, <4 x i1> %mask, i32 %evl) 20387 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) 20388 declare void @llvm.vp.scatter.v2f32.v2p2f32(<2 x float> %val, <2 x float addrspace(2)*> %ptrs, <2 x i1> %mask, i32 %evl) 20389 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) 20390 20391Overview: 20392""""""""" 20393 20394The '``llvm.vp.scatter.*``' intrinsic is the vector length predicated version of 20395the :ref:`llvm.masked.scatter <int_mscatter>` intrinsic. 20396 20397Arguments: 20398"""""""""" 20399 20400The first operand is a vector value to be written to memory. The second operand 20401is a vector of pointers, pointing to where the value elements should be stored. 20402The third operand is a vector of boolean values with the same number of 20403elements as the return type. The fourth is the explicit vector length of the 20404operation. 20405 20406The :ref:`align <attr_align>` parameter attribute can be provided for the 20407second operand. 20408 20409Semantics: 20410"""""""""" 20411 20412The '``llvm.vp.scatter``' intrinsic writes multiple scalar values to memory in 20413the same way as the '``llvm.masked.scatter``' intrinsic, where the mask is 20414taken from the combination of the '``mask``' and '``evl``' operands in the 20415usual VP way. The '``alignment``' operand of the '``llvm.masked.scatter``' does 20416not have a corresponding operand in '``llvm.vp.scatter``': it is instead 20417provided via the optional ``align`` parameter attribute on the 20418vector-of-pointers operand. Otherwise it is taken as the ABI alignment of the 20419destination addresses as specified by the :ref:`datalayout 20420string<langref_datalayout>`. 20421 20422Examples: 20423""""""""" 20424 20425.. code-block:: text 20426 20427 call void @llvm.vp.scatter.v8i8.v8p0i8(<8 x i8> %val, <8 x i8*> align 1 %ptrs, <8 x i1> %mask, i32 %evl) 20428 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below. 20429 20430 call void @llvm.masked.scatter.v8i8.v8p0i8(<8 x i8> %val, <8 x i8*> %ptrs, i32 1, <8 x i1> %mask) 20431 20432 20433.. _int_vp_trunc: 20434 20435'``llvm.vp.trunc.*``' Intrinsics 20436^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20437 20438Syntax: 20439""""""" 20440This is an overloaded intrinsic. 20441 20442:: 20443 20444 declare <16 x i16> @llvm.vp.trunc.v16i16.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 20445 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>) 20446 20447Overview: 20448""""""""" 20449 20450The '``llvm.vp.trunc``' intrinsic truncates its first operand to the return 20451type. The operation has a mask and an explicit vector length parameter. 20452 20453 20454Arguments: 20455"""""""""" 20456 20457The '``llvm.vp.trunc``' intrinsic takes a value to cast as its first operand. 20458The return type is the type to cast the value to. Both types must be vector of 20459:ref:`integer <t_integer>` type. The bit size of the value must be larger than 20460the bit size of the return type. The second operand is the vector mask. The 20461return type, the value to cast, and the vector mask have the same number of 20462elements. The third operand is the explicit vector length of the operation. 20463 20464Semantics: 20465"""""""""" 20466 20467The '``llvm.vp.trunc``' intrinsic truncates the high order bits in value and 20468converts the remaining bits to return type. Since the source size must be larger 20469than the destination size, '``llvm.vp.trunc``' cannot be a *no-op cast*. It will 20470always truncate bits. The conversion is performed on lane positions below the 20471explicit vector length and where the vector mask is true. Masked-off lanes are 20472undefined. 20473 20474Examples: 20475""""""""" 20476 20477.. code-block:: llvm 20478 20479 %r = call <4 x i16> @llvm.vp.trunc.v4i16.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 20480 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20481 20482 %t = trunc <4 x i32> %a to <4 x i16> 20483 %also.r = select <4 x i1> %mask, <4 x i16> %t, <4 x i16> undef 20484 20485 20486.. _int_vp_zext: 20487 20488'``llvm.vp.zext.*``' Intrinsics 20489^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20490 20491Syntax: 20492""""""" 20493This is an overloaded intrinsic. 20494 20495:: 20496 20497 declare <16 x i32> @llvm.vp.zext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>) 20498 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>) 20499 20500Overview: 20501""""""""" 20502 20503The '``llvm.vp.zext``' intrinsic zero extends its first operand to the return 20504type. The operation has a mask and an explicit vector length parameter. 20505 20506 20507Arguments: 20508"""""""""" 20509 20510The '``llvm.vp.zext``' intrinsic takes a value to cast as its first operand. 20511The return type is the type to cast the value to. Both types must be vectors of 20512:ref:`integer <t_integer>` type. The bit size of the value must be smaller than 20513the bit size of the return type. The second operand is the vector mask. The 20514return type, the value to cast, and the vector mask have the same number of 20515elements. The third operand is the explicit vector length of the operation. 20516 20517Semantics: 20518"""""""""" 20519 20520The '``llvm.vp.zext``' intrinsic fill the high order bits of the value with zero 20521bits until it reaches the size of the return type. When zero extending from i1, 20522the result will always be either 0 or 1. The conversion is performed on lane 20523positions below the explicit vector length and where the vector mask is true. 20524Masked-off lanes are undefined. 20525 20526Examples: 20527""""""""" 20528 20529.. code-block:: llvm 20530 20531 %r = call <4 x i32> @llvm.vp.zext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl) 20532 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20533 20534 %t = zext <4 x i16> %a to <4 x i32> 20535 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 20536 20537 20538.. _int_vp_sext: 20539 20540'``llvm.vp.sext.*``' Intrinsics 20541^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20542 20543Syntax: 20544""""""" 20545This is an overloaded intrinsic. 20546 20547:: 20548 20549 declare <16 x i32> @llvm.vp.sext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>) 20550 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>) 20551 20552Overview: 20553""""""""" 20554 20555The '``llvm.vp.sext``' intrinsic sign extends its first operand to the return 20556type. The operation has a mask and an explicit vector length parameter. 20557 20558 20559Arguments: 20560"""""""""" 20561 20562The '``llvm.vp.sext``' intrinsic takes a value to cast as its first operand. 20563The return type is the type to cast the value to. Both types must be vectors of 20564:ref:`integer <t_integer>` type. The bit size of the value must be smaller than 20565the bit size of the return type. The second operand is the vector mask. The 20566return type, the value to cast, and the vector mask have the same number of 20567elements. The third operand is the explicit vector length of the operation. 20568 20569Semantics: 20570"""""""""" 20571 20572The '``llvm.vp.sext``' intrinsic performs a sign extension by copying the sign 20573bit (highest order bit) of the value until it reaches the size of the return 20574type. When zero extending from i1, the result will always be either -1 or 0. 20575The conversion is performed on lane positions below the explicit vector length 20576and where the vector mask is true. Masked-off lanes are undefined. 20577 20578Examples: 20579""""""""" 20580 20581.. code-block:: llvm 20582 20583 %r = call <4 x i32> @llvm.vp.sext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl) 20584 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20585 20586 %t = sext <4 x i16> %a to <4 x i32> 20587 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 20588 20589 20590.. _int_vp_fptrunc: 20591 20592'``llvm.vp.fptrunc.*``' Intrinsics 20593^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20594 20595Syntax: 20596""""""" 20597This is an overloaded intrinsic. 20598 20599:: 20600 20601 declare <16 x float> @llvm.vp.fptrunc.v16f32.v16f64 (<16 x double> <op>, <16 x i1> <mask>, i32 <vector_length>) 20602 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>) 20603 20604Overview: 20605""""""""" 20606 20607The '``llvm.vp.fptrunc``' intrinsic truncates its first operand to the return 20608type. The operation has a mask and an explicit vector length parameter. 20609 20610 20611Arguments: 20612"""""""""" 20613 20614The '``llvm.vp.fptrunc``' intrinsic takes a value to cast as its first operand. 20615The return type is the type to cast the value to. Both types must be vector of 20616:ref:`floating-point <t_floating>` type. The bit size of the value must be 20617larger than the bit size of the return type. This implies that 20618'``llvm.vp.fptrunc``' cannot be used to make a *no-op cast*. The second operand 20619is the vector mask. The return type, the value to cast, and the vector mask have 20620the same number of elements. The third operand is the explicit vector length of 20621the operation. 20622 20623Semantics: 20624"""""""""" 20625 20626The '``llvm.vp.fptrunc``' intrinsic casts a ``value`` from a larger 20627:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 20628<t_floating>` type. 20629This instruction is assumed to execute in the default :ref:`floating-point 20630environment <floatenv>`. The conversion is performed on lane positions below the 20631explicit vector length and where the vector mask is true. Masked-off lanes are 20632undefined. 20633 20634Examples: 20635""""""""" 20636 20637.. code-block:: llvm 20638 20639 %r = call <4 x float> @llvm.vp.fptrunc.v4f32.v4f64(<4 x double> %a, <4 x i1> %mask, i32 %evl) 20640 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20641 20642 %t = fptrunc <4 x double> %a to <4 x float> 20643 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 20644 20645 20646.. _int_vp_fpext: 20647 20648'``llvm.vp.fpext.*``' Intrinsics 20649^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20650 20651Syntax: 20652""""""" 20653This is an overloaded intrinsic. 20654 20655:: 20656 20657 declare <16 x double> @llvm.vp.fpext.v16f64.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 20658 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>) 20659 20660Overview: 20661""""""""" 20662 20663The '``llvm.vp.fpext``' intrinsic extends its first operand to the return 20664type. The operation has a mask and an explicit vector length parameter. 20665 20666 20667Arguments: 20668"""""""""" 20669 20670The '``llvm.vp.fpext``' intrinsic takes a value to cast as its first operand. 20671The return type is the type to cast the value to. Both types must be vector of 20672:ref:`floating-point <t_floating>` type. The bit size of the value must be 20673smaller than the bit size of the return type. This implies that 20674'``llvm.vp.fpext``' cannot be used to make a *no-op cast*. The second operand 20675is the vector mask. The return type, the value to cast, and the vector mask have 20676the same number of elements. The third operand is the explicit vector length of 20677the operation. 20678 20679Semantics: 20680"""""""""" 20681 20682The '``llvm.vp.fpext``' intrinsic extends the ``value`` from a smaller 20683:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point 20684<t_floating>` type. The '``llvm.vp.fpext``' cannot be used to make a 20685*no-op cast* because it always changes bits. Use ``bitcast`` to make a 20686*no-op cast* for a floating-point cast. 20687The conversion is performed on lane positions below the explicit vector length 20688and where the vector mask is true. Masked-off lanes are undefined. 20689 20690Examples: 20691""""""""" 20692 20693.. code-block:: llvm 20694 20695 %r = call <4 x double> @llvm.vp.fpext.v4f64.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 20696 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20697 20698 %t = fpext <4 x float> %a to <4 x double> 20699 %also.r = select <4 x i1> %mask, <4 x double> %t, <4 x double> undef 20700 20701 20702.. _int_vp_fptoui: 20703 20704'``llvm.vp.fptoui.*``' Intrinsics 20705^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20706 20707Syntax: 20708""""""" 20709This is an overloaded intrinsic. 20710 20711:: 20712 20713 declare <16 x i32> @llvm.vp.fptoui.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 20714 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>) 20715 declare <256 x i64> @llvm.vp.fptoui.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 20716 20717Overview: 20718""""""""" 20719 20720The '``llvm.vp.fptoui``' intrinsic converts the :ref:`floating-point 20721<t_floating>` operand to the unsigned integer return type. 20722The operation has a mask and an explicit vector length parameter. 20723 20724 20725Arguments: 20726"""""""""" 20727 20728The '``llvm.vp.fptoui``' intrinsic takes a value to cast as its first operand. 20729The value to cast must be a vector of :ref:`floating-point <t_floating>` type. 20730The return type is the type to cast the value to. The return type must be 20731vector of :ref:`integer <t_integer>` type. The second operand is the vector 20732mask. The return type, the value to cast, and the vector mask have the same 20733number of elements. The third operand is the explicit vector length of the 20734operation. 20735 20736Semantics: 20737"""""""""" 20738 20739The '``llvm.vp.fptoui``' intrinsic converts its :ref:`floating-point 20740<t_floating>` operand into the nearest (rounding towards zero) unsigned integer 20741value where the lane position is below the explicit vector length and the 20742vector mask is true. Masked-off lanes are undefined. On enabled lanes where 20743conversion takes place and the value cannot fit in the return type, the result 20744on that lane is a :ref:`poison value <poisonvalues>`. 20745 20746Examples: 20747""""""""" 20748 20749.. code-block:: llvm 20750 20751 %r = call <4 x i32> @llvm.vp.fptoui.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 20752 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20753 20754 %t = fptoui <4 x float> %a to <4 x i32> 20755 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 20756 20757 20758.. _int_vp_fptosi: 20759 20760'``llvm.vp.fptosi.*``' Intrinsics 20761^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20762 20763Syntax: 20764""""""" 20765This is an overloaded intrinsic. 20766 20767:: 20768 20769 declare <16 x i32> @llvm.vp.fptosi.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 20770 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>) 20771 declare <256 x i64> @llvm.vp.fptosi.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 20772 20773Overview: 20774""""""""" 20775 20776The '``llvm.vp.fptosi``' intrinsic converts the :ref:`floating-point 20777<t_floating>` operand to the signed integer return type. 20778The operation has a mask and an explicit vector length parameter. 20779 20780 20781Arguments: 20782"""""""""" 20783 20784The '``llvm.vp.fptosi``' intrinsic takes a value to cast as its first operand. 20785The value to cast must be a vector of :ref:`floating-point <t_floating>` type. 20786The return type is the type to cast the value to. The return type must be 20787vector of :ref:`integer <t_integer>` type. The second operand is the vector 20788mask. The return type, the value to cast, and the vector mask have the same 20789number of elements. The third operand is the explicit vector length of the 20790operation. 20791 20792Semantics: 20793"""""""""" 20794 20795The '``llvm.vp.fptosi``' intrinsic converts its :ref:`floating-point 20796<t_floating>` operand into the nearest (rounding towards zero) signed integer 20797value where the lane position is below the explicit vector length and the 20798vector mask is true. Masked-off lanes are undefined. On enabled lanes where 20799conversion takes place and the value cannot fit in the return type, the result 20800on that lane is a :ref:`poison value <poisonvalues>`. 20801 20802Examples: 20803""""""""" 20804 20805.. code-block:: llvm 20806 20807 %r = call <4 x i32> @llvm.vp.fptosi.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 20808 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20809 20810 %t = fptosi <4 x float> %a to <4 x i32> 20811 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 20812 20813 20814.. _int_vp_uitofp: 20815 20816'``llvm.vp.uitofp.*``' Intrinsics 20817^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20818 20819Syntax: 20820""""""" 20821This is an overloaded intrinsic. 20822 20823:: 20824 20825 declare <16 x float> @llvm.vp.uitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 20826 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>) 20827 declare <256 x double> @llvm.vp.uitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>) 20828 20829Overview: 20830""""""""" 20831 20832The '``llvm.vp.uitofp``' intrinsic converts its unsigned integer operand to the 20833:ref:`floating-point <t_floating>` return type. The operation has a mask and 20834an explicit vector length parameter. 20835 20836 20837Arguments: 20838"""""""""" 20839 20840The '``llvm.vp.uitofp``' intrinsic takes a value to cast as its first operand. 20841The value to cast must be vector of :ref:`integer <t_integer>` type. The 20842return type is the type to cast the value to. The return type must be a vector 20843of :ref:`floating-point <t_floating>` type. The second operand is the vector 20844mask. The return type, the value to cast, and the vector mask have the same 20845number of elements. The third operand is the explicit vector length of the 20846operation. 20847 20848Semantics: 20849"""""""""" 20850 20851The '``llvm.vp.uitofp``' intrinsic interprets its first operand as an unsigned 20852integer quantity and converts it to the corresponding floating-point value. If 20853the value cannot be exactly represented, it is rounded using the default 20854rounding mode. The conversion is performed on lane positions below the 20855explicit vector length and where the vector mask is true. Masked-off lanes are 20856undefined. 20857 20858Examples: 20859""""""""" 20860 20861.. code-block:: llvm 20862 20863 %r = call <4 x float> @llvm.vp.uitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 20864 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20865 20866 %t = uitofp <4 x i32> %a to <4 x float> 20867 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 20868 20869 20870.. _int_vp_sitofp: 20871 20872'``llvm.vp.sitofp.*``' Intrinsics 20873^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20874 20875Syntax: 20876""""""" 20877This is an overloaded intrinsic. 20878 20879:: 20880 20881 declare <16 x float> @llvm.vp.sitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 20882 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>) 20883 declare <256 x double> @llvm.vp.sitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>) 20884 20885Overview: 20886""""""""" 20887 20888The '``llvm.vp.sitofp``' intrinsic converts its signed integer operand to the 20889:ref:`floating-point <t_floating>` return type. The operation has a mask and 20890an explicit vector length parameter. 20891 20892 20893Arguments: 20894"""""""""" 20895 20896The '``llvm.vp.sitofp``' intrinsic takes a value to cast as its first operand. 20897The value to cast must be vector of :ref:`integer <t_integer>` type. The 20898return type is the type to cast the value to. The return type must be a vector 20899of :ref:`floating-point <t_floating>` type. The second operand is the vector 20900mask. The return type, the value to cast, and the vector mask have the same 20901number of elements. The third operand is the explicit vector length of the 20902operation. 20903 20904Semantics: 20905"""""""""" 20906 20907The '``llvm.vp.sitofp``' intrinsic interprets its first operand as a signed 20908integer quantity and converts it to the corresponding floating-point value. If 20909the value cannot be exactly represented, it is rounded using the default 20910rounding mode. The conversion is performed on lane positions below the 20911explicit vector length and where the vector mask is true. Masked-off lanes are 20912undefined. 20913 20914Examples: 20915""""""""" 20916 20917.. code-block:: llvm 20918 20919 %r = call <4 x float> @llvm.vp.sitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 20920 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20921 20922 %t = sitofp <4 x i32> %a to <4 x float> 20923 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 20924 20925 20926.. _int_vp_ptrtoint: 20927 20928'``llvm.vp.ptrtoint.*``' Intrinsics 20929^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20930 20931Syntax: 20932""""""" 20933This is an overloaded intrinsic. 20934 20935:: 20936 20937 declare <16 x i8> @llvm.vp.ptrtoint.v16i8.v16p0i32 (<16 x i32*> <op>, <16 x i1> <mask>, i32 <vector_length>) 20938 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>) 20939 declare <256 x i64> @llvm.vp.ptrtoint.v16i64.v16p0i32 (<256 x i32*> <op>, <256 x i1> <mask>, i32 <vector_length>) 20940 20941Overview: 20942""""""""" 20943 20944The '``llvm.vp.ptrtoint``' intrinsic converts its pointer to the integer return 20945type. The operation has a mask and an explicit vector length parameter. 20946 20947 20948Arguments: 20949"""""""""" 20950 20951The '``llvm.vp.ptrtoint``' intrinsic takes a value to cast as its first operand 20952, which must be a vector of pointers, and a type to cast it to return type, 20953which must be a vector of :ref:`integer <t_integer>` type. 20954The second operand is the vector mask. The return type, the value to cast, and 20955the vector mask have the same number of elements. 20956The third operand is the explicit vector length of the operation. 20957 20958Semantics: 20959"""""""""" 20960 20961The '``llvm.vp.ptrtoint``' intrinsic converts value to return type by 20962interpreting the pointer value as an integer and either truncating or zero 20963extending that value to the size of the integer type. 20964If ``value`` is smaller than return type, then a zero extension is done. If 20965``value`` is larger than return type, then a truncation is done. If they are 20966the same size, then nothing is done (*no-op cast*) other than a type 20967change. 20968The conversion is performed on lane positions below the explicit vector length 20969and where the vector mask is true. Masked-off lanes are undefined. 20970 20971Examples: 20972""""""""" 20973 20974.. code-block:: llvm 20975 20976 %r = call <4 x i8> @llvm.vp.ptrtoint.v4i8.v4p0i32(<4 x i32*> %a, <4 x i1> %mask, i32 %evl) 20977 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20978 20979 %t = ptrtoint <4 x i32*> %a to <4 x i8> 20980 %also.r = select <4 x i1> %mask, <4 x i8> %t, <4 x i8> undef 20981 20982 20983.. _int_vp_inttoptr: 20984 20985'``llvm.vp.inttoptr.*``' Intrinsics 20986^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20987 20988Syntax: 20989""""""" 20990This is an overloaded intrinsic. 20991 20992:: 20993 20994 declare <16 x i32*> @llvm.vp.inttoptr.v16p0i32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 20995 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>) 20996 declare <256 x i32*> @llvm.vp.inttoptr.v256p0i32.v256i32 (<256 x i32> <op>, <256 x i1> <mask>, i32 <vector_length>) 20997 20998Overview: 20999""""""""" 21000 21001The '``llvm.vp.inttoptr``' intrinsic converts its integer value to the point 21002return type. The operation has a mask and an explicit vector length parameter. 21003 21004 21005Arguments: 21006"""""""""" 21007 21008The '``llvm.vp.inttoptr``' intrinsic takes a value to cast as its first operand 21009, which must be a vector of :ref:`integer <t_integer>` type, and a type to cast 21010it to return type, which must be a vector of pointers type. 21011The second operand is the vector mask. The return type, the value to cast, and 21012the vector mask have the same number of elements. 21013The third operand is the explicit vector length of the operation. 21014 21015Semantics: 21016"""""""""" 21017 21018The '``llvm.vp.inttoptr``' intrinsic converts ``value`` to return type by 21019applying either a zero extension or a truncation depending on the size of the 21020integer ``value``. If ``value`` is larger than the size of a pointer, then a 21021truncation is done. If ``value`` is smaller than the size of a pointer, then a 21022zero extension is done. If they are the same size, nothing is done (*no-op cast*). 21023The conversion is performed on lane positions below the explicit vector length 21024and where the vector mask is true. Masked-off lanes are undefined. 21025 21026Examples: 21027""""""""" 21028 21029.. code-block:: llvm 21030 21031 %r = call <4 x i32*> @llvm.vp.inttoptr.v4p0i32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 21032 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21033 21034 %t = inttoptr <4 x i32> %a to <4 x i32*> 21035 %also.r = select <4 x i1> %mask, <4 x i32*> %t, <4 x i32*> undef 21036 21037 21038.. _int_vp_fcmp: 21039 21040'``llvm.vp.fcmp.*``' Intrinsics 21041^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21042 21043Syntax: 21044""""""" 21045This is an overloaded intrinsic. 21046 21047:: 21048 21049 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>) 21050 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>) 21051 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>) 21052 21053Overview: 21054""""""""" 21055 21056The '``llvm.vp.fcmp``' intrinsic returns a vector of boolean values based on 21057the comparison of its operands. The operation has a mask and an explicit vector 21058length parameter. 21059 21060 21061Arguments: 21062"""""""""" 21063 21064The '``llvm.vp.fcmp``' intrinsic takes the two values to compare as its first 21065and second operands. These two values must be vectors of :ref:`floating-point 21066<t_floating>` types. 21067The return type is the result of the comparison. The return type must be a 21068vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask. 21069The return type, the values to compare, and the vector mask have the same 21070number of elements. The third operand is the condition code indicating the kind 21071of comparison to perform. It must be a metadata string with :ref:`one of the 21072supported floating-point condition code values <fcmp_md_cc>`. The fifth operand 21073is the explicit vector length of the operation. 21074 21075Semantics: 21076"""""""""" 21077 21078The '``llvm.vp.fcmp``' compares its first two operands according to the 21079condition code given as the third operand. The operands are compared element by 21080element on each enabled lane, where the the semantics of the comparison are 21081defined :ref:`according to the condition code <fcmp_md_cc_sem>`. Masked-off 21082lanes are undefined. 21083 21084Examples: 21085""""""""" 21086 21087.. code-block:: llvm 21088 21089 %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) 21090 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21091 21092 %t = fcmp oeq <4 x float> %a, %b 21093 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> undef 21094 21095 21096.. _int_vp_icmp: 21097 21098'``llvm.vp.icmp.*``' Intrinsics 21099^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21100 21101Syntax: 21102""""""" 21103This is an overloaded intrinsic. 21104 21105:: 21106 21107 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>) 21108 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>) 21109 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>) 21110 21111Overview: 21112""""""""" 21113 21114The '``llvm.vp.icmp``' intrinsic returns a vector of boolean values based on 21115the comparison of its operands. The operation has a mask and an explicit vector 21116length parameter. 21117 21118 21119Arguments: 21120"""""""""" 21121 21122The '``llvm.vp.icmp``' intrinsic takes the two values to compare as its first 21123and second operands. These two values must be vectors of :ref:`integer 21124<t_integer>` types. 21125The return type is the result of the comparison. The return type must be a 21126vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask. 21127The return type, the values to compare, and the vector mask have the same 21128number of elements. The third operand is the condition code indicating the kind 21129of comparison to perform. It must be a metadata string with :ref:`one of the 21130supported integer condition code values <icmp_md_cc>`. The fifth operand is the 21131explicit vector length of the operation. 21132 21133Semantics: 21134"""""""""" 21135 21136The '``llvm.vp.icmp``' compares its first two operands according to the 21137condition code given as the third operand. The operands are compared element by 21138element on each enabled lane, where the the semantics of the comparison are 21139defined :ref:`according to the condition code <icmp_md_cc_sem>`. Masked-off 21140lanes are undefined. 21141 21142Examples: 21143""""""""" 21144 21145.. code-block:: llvm 21146 21147 %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) 21148 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21149 21150 %t = icmp ne <4 x i32> %a, %b 21151 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> undef 21152 21153 21154.. _int_mload_mstore: 21155 21156Masked Vector Load and Store Intrinsics 21157--------------------------------------- 21158 21159LLVM 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. 21160 21161.. _int_mload: 21162 21163'``llvm.masked.load.*``' Intrinsics 21164^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21165 21166Syntax: 21167""""""" 21168This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type. 21169 21170:: 21171 21172 declare <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 21173 declare <2 x double> @llvm.masked.load.v2f64.p0v2f64 (<2 x double>* <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>) 21174 ;; The data is a vector of pointers to double 21175 declare <8 x double*> @llvm.masked.load.v8p0f64.p0v8p0f64 (<8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x double*> <passthru>) 21176 ;; The data is a vector of function pointers 21177 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>) 21178 21179Overview: 21180""""""""" 21181 21182Reads 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. 21183 21184 21185Arguments: 21186"""""""""" 21187 21188The 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. 21189 21190Semantics: 21191"""""""""" 21192 21193The '``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. 21194The 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. 21195 21196 21197:: 21198 21199 %res = call <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru) 21200 21201 ;; The result of the two following instructions is identical aside from potential memory access exception 21202 %loadlal = load <16 x float>, <16 x float>* %ptr, align 4 21203 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru 21204 21205.. _int_mstore: 21206 21207'``llvm.masked.store.*``' Intrinsics 21208^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21209 21210Syntax: 21211""""""" 21212This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type. 21213 21214:: 21215 21216 declare void @llvm.masked.store.v8i32.p0v8i32 (<8 x i32> <value>, <8 x i32>* <ptr>, i32 <alignment>, <8 x i1> <mask>) 21217 declare void @llvm.masked.store.v16f32.p0v16f32 (<16 x float> <value>, <16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>) 21218 ;; The data is a vector of pointers to double 21219 declare void @llvm.masked.store.v8p0f64.p0v8p0f64 (<8 x double*> <value>, <8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>) 21220 ;; The data is a vector of function pointers 21221 declare void @llvm.masked.store.v4p0f_i32f.p0v4p0f_i32f (<4 x i32 ()*> <value>, <4 x i32 ()*>* <ptr>, i32 <alignment>, <4 x i1> <mask>) 21222 21223Overview: 21224""""""""" 21225 21226Writes 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. 21227 21228Arguments: 21229"""""""""" 21230 21231The 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. 21232 21233 21234Semantics: 21235"""""""""" 21236 21237The '``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. 21238The 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. 21239 21240:: 21241 21242 call void @llvm.masked.store.v16f32.p0v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4, <16 x i1> %mask) 21243 21244 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions 21245 %oldval = load <16 x float>, <16 x float>* %ptr, align 4 21246 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval 21247 store <16 x float> %res, <16 x float>* %ptr, align 4 21248 21249 21250Masked Vector Gather and Scatter Intrinsics 21251------------------------------------------- 21252 21253LLVM 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. 21254 21255.. _int_mgather: 21256 21257'``llvm.masked.gather.*``' Intrinsics 21258^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21259 21260Syntax: 21261""""""" 21262This 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. 21263 21264:: 21265 21266 declare <16 x float> @llvm.masked.gather.v16f32.v16p0f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 21267 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>) 21268 declare <8 x float*> @llvm.masked.gather.v8p0f32.v8p0p0f32 (<8 x float**> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x float*> <passthru>) 21269 21270Overview: 21271""""""""" 21272 21273Reads 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. 21274 21275 21276Arguments: 21277"""""""""" 21278 21279The 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. 21280 21281Semantics: 21282"""""""""" 21283 21284The '``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. 21285The 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. 21286 21287 21288:: 21289 21290 %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) 21291 21292 ;; The gather with all-true mask is equivalent to the following instruction sequence 21293 %ptr0 = extractelement <4 x double*> %ptrs, i32 0 21294 %ptr1 = extractelement <4 x double*> %ptrs, i32 1 21295 %ptr2 = extractelement <4 x double*> %ptrs, i32 2 21296 %ptr3 = extractelement <4 x double*> %ptrs, i32 3 21297 21298 %val0 = load double, double* %ptr0, align 8 21299 %val1 = load double, double* %ptr1, align 8 21300 %val2 = load double, double* %ptr2, align 8 21301 %val3 = load double, double* %ptr3, align 8 21302 21303 %vec0 = insertelement <4 x double>undef, %val0, 0 21304 %vec01 = insertelement <4 x double>%vec0, %val1, 1 21305 %vec012 = insertelement <4 x double>%vec01, %val2, 2 21306 %vec0123 = insertelement <4 x double>%vec012, %val3, 3 21307 21308.. _int_mscatter: 21309 21310'``llvm.masked.scatter.*``' Intrinsics 21311^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21312 21313Syntax: 21314""""""" 21315This 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. 21316 21317:: 21318 21319 declare void @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>) 21320 declare void @llvm.masked.scatter.v16f32.v16p1f32 (<16 x float> <value>, <16 x float addrspace(1)*> <ptrs>, i32 <alignment>, <16 x i1> <mask>) 21321 declare void @llvm.masked.scatter.v4p0f64.v4p0p0f64 (<4 x double*> <value>, <4 x double**> <ptrs>, i32 <alignment>, <4 x i1> <mask>) 21322 21323Overview: 21324""""""""" 21325 21326Writes 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. 21327 21328Arguments: 21329"""""""""" 21330 21331The 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. 21332 21333Semantics: 21334"""""""""" 21335 21336The '``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. 21337 21338:: 21339 21340 ;; This instruction unconditionally stores data vector in multiple addresses 21341 call @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4, <8 x i1> <true, true, .. true>) 21342 21343 ;; It is equivalent to a list of scalar stores 21344 %val0 = extractelement <8 x i32> %value, i32 0 21345 %val1 = extractelement <8 x i32> %value, i32 1 21346 .. 21347 %val7 = extractelement <8 x i32> %value, i32 7 21348 %ptr0 = extractelement <8 x i32*> %ptrs, i32 0 21349 %ptr1 = extractelement <8 x i32*> %ptrs, i32 1 21350 .. 21351 %ptr7 = extractelement <8 x i32*> %ptrs, i32 7 21352 ;; Note: the order of the following stores is important when they overlap: 21353 store i32 %val0, i32* %ptr0, align 4 21354 store i32 %val1, i32* %ptr1, align 4 21355 .. 21356 store i32 %val7, i32* %ptr7, align 4 21357 21358 21359Masked Vector Expanding Load and Compressing Store Intrinsics 21360------------------------------------------------------------- 21361 21362LLVM 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>`. 21363 21364.. _int_expandload: 21365 21366'``llvm.masked.expandload.*``' Intrinsics 21367^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21368 21369Syntax: 21370""""""" 21371This 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. 21372 21373:: 21374 21375 declare <16 x float> @llvm.masked.expandload.v16f32 (float* <ptr>, <16 x i1> <mask>, <16 x float> <passthru>) 21376 declare <2 x i64> @llvm.masked.expandload.v2i64 (i64* <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>) 21377 21378Overview: 21379""""""""" 21380 21381Reads 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. 21382 21383 21384Arguments: 21385"""""""""" 21386 21387The 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. 21388 21389Semantics: 21390"""""""""" 21391 21392The '``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: 21393 21394.. code-block:: c 21395 21396 // In this loop we load from B and spread the elements into array A. 21397 double *A, B; int *C; 21398 for (int i = 0; i < size; ++i) { 21399 if (C[i] != 0) 21400 A[i] = B[j++]; 21401 } 21402 21403 21404.. code-block:: llvm 21405 21406 ; Load several elements from array B and expand them in a vector. 21407 ; The number of loaded elements is equal to the number of '1' elements in the Mask. 21408 %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(double* %Bptr, <8 x i1> %Mask, <8 x double> undef) 21409 ; Store the result in A 21410 call void @llvm.masked.store.v8f64.p0v8f64(<8 x double> %Tmp, <8 x double>* %Aptr, i32 8, <8 x i1> %Mask) 21411 21412 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask. 21413 %MaskI = bitcast <8 x i1> %Mask to i8 21414 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI) 21415 %MaskI64 = zext i8 %MaskIPopcnt to i64 21416 %BNextInd = add i64 %BInd, %MaskI64 21417 21418 21419Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles. 21420If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load. 21421 21422.. _int_compressstore: 21423 21424'``llvm.masked.compressstore.*``' Intrinsics 21425^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21426 21427Syntax: 21428""""""" 21429This 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. 21430 21431:: 21432 21433 declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, i32* <ptr>, <8 x i1> <mask>) 21434 declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, float* <ptr>, <16 x i1> <mask>) 21435 21436Overview: 21437""""""""" 21438 21439Selects 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. 21440 21441Arguments: 21442"""""""""" 21443 21444The 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. 21445 21446 21447Semantics: 21448"""""""""" 21449 21450The '``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: 21451 21452.. code-block:: c 21453 21454 // In this loop we load elements from A and store them consecutively in B 21455 double *A, B; int *C; 21456 for (int i = 0; i < size; ++i) { 21457 if (C[i] != 0) 21458 B[j++] = A[i] 21459 } 21460 21461 21462.. code-block:: llvm 21463 21464 ; Load elements from A. 21465 %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0v8f64(<8 x double>* %Aptr, i32 8, <8 x i1> %Mask, <8 x double> undef) 21466 ; Store all selected elements consecutively in array B 21467 call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, double* %Bptr, <8 x i1> %Mask) 21468 21469 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask. 21470 %MaskI = bitcast <8 x i1> %Mask to i8 21471 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI) 21472 %MaskI64 = zext i8 %MaskIPopcnt to i64 21473 %BNextInd = add i64 %BInd, %MaskI64 21474 21475 21476Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations. 21477 21478 21479Memory Use Markers 21480------------------ 21481 21482This class of intrinsics provides information about the 21483:ref:`lifetime of memory objects <objectlifetime>` and ranges where variables 21484are immutable. 21485 21486.. _int_lifestart: 21487 21488'``llvm.lifetime.start``' Intrinsic 21489^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21490 21491Syntax: 21492""""""" 21493 21494:: 21495 21496 declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>) 21497 21498Overview: 21499""""""""" 21500 21501The '``llvm.lifetime.start``' intrinsic specifies the start of a memory 21502object's lifetime. 21503 21504Arguments: 21505"""""""""" 21506 21507The first argument is a constant integer representing the size of the 21508object, or -1 if it is variable sized. The second argument is a pointer 21509to the object. 21510 21511Semantics: 21512"""""""""" 21513 21514If ``ptr`` is a stack-allocated object and it points to the first byte of 21515the object, the object is initially marked as dead. 21516``ptr`` is conservatively considered as a non-stack-allocated object if 21517the stack coloring algorithm that is used in the optimization pipeline cannot 21518conclude that ``ptr`` is a stack-allocated object. 21519 21520After '``llvm.lifetime.start``', the stack object that ``ptr`` points is marked 21521as alive and has an uninitialized value. 21522The stack object is marked as dead when either 21523:ref:`llvm.lifetime.end <int_lifeend>` to the alloca is executed or the 21524function returns. 21525 21526After :ref:`llvm.lifetime.end <int_lifeend>` is called, 21527'``llvm.lifetime.start``' on the stack object can be called again. 21528The second '``llvm.lifetime.start``' call marks the object as alive, but it 21529does not change the address of the object. 21530 21531If ``ptr`` is a non-stack-allocated object, it does not point to the first 21532byte of the object or it is a stack object that is already alive, it simply 21533fills all bytes of the object with ``poison``. 21534 21535 21536.. _int_lifeend: 21537 21538'``llvm.lifetime.end``' Intrinsic 21539^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21540 21541Syntax: 21542""""""" 21543 21544:: 21545 21546 declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>) 21547 21548Overview: 21549""""""""" 21550 21551The '``llvm.lifetime.end``' intrinsic specifies the end of a memory object's 21552lifetime. 21553 21554Arguments: 21555"""""""""" 21556 21557The first argument is a constant integer representing the size of the 21558object, or -1 if it is variable sized. The second argument is a pointer 21559to the object. 21560 21561Semantics: 21562"""""""""" 21563 21564If ``ptr`` is a stack-allocated object and it points to the first byte of the 21565object, the object is dead. 21566``ptr`` is conservatively considered as a non-stack-allocated object if 21567the stack coloring algorithm that is used in the optimization pipeline cannot 21568conclude that ``ptr`` is a stack-allocated object. 21569 21570Calling ``llvm.lifetime.end`` on an already dead alloca is no-op. 21571 21572If ``ptr`` is a non-stack-allocated object or it does not point to the first 21573byte of the object, it is equivalent to simply filling all bytes of the object 21574with ``poison``. 21575 21576 21577'``llvm.invariant.start``' Intrinsic 21578^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21579 21580Syntax: 21581""""""" 21582This is an overloaded intrinsic. The memory object can belong to any address space. 21583 21584:: 21585 21586 declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>) 21587 21588Overview: 21589""""""""" 21590 21591The '``llvm.invariant.start``' intrinsic specifies that the contents of 21592a memory object will not change. 21593 21594Arguments: 21595"""""""""" 21596 21597The first argument is a constant integer representing the size of the 21598object, or -1 if it is variable sized. The second argument is a pointer 21599to the object. 21600 21601Semantics: 21602"""""""""" 21603 21604This intrinsic indicates that until an ``llvm.invariant.end`` that uses 21605the return value, the referenced memory location is constant and 21606unchanging. 21607 21608'``llvm.invariant.end``' Intrinsic 21609^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21610 21611Syntax: 21612""""""" 21613This is an overloaded intrinsic. The memory object can belong to any address space. 21614 21615:: 21616 21617 declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>) 21618 21619Overview: 21620""""""""" 21621 21622The '``llvm.invariant.end``' intrinsic specifies that the contents of a 21623memory object are mutable. 21624 21625Arguments: 21626"""""""""" 21627 21628The first argument is the matching ``llvm.invariant.start`` intrinsic. 21629The second argument is a constant integer representing the size of the 21630object, or -1 if it is variable sized and the third argument is a 21631pointer to the object. 21632 21633Semantics: 21634"""""""""" 21635 21636This intrinsic indicates that the memory is mutable again. 21637 21638'``llvm.launder.invariant.group``' Intrinsic 21639^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21640 21641Syntax: 21642""""""" 21643This is an overloaded intrinsic. The memory object can belong to any address 21644space. The returned pointer must belong to the same address space as the 21645argument. 21646 21647:: 21648 21649 declare i8* @llvm.launder.invariant.group.p0i8(i8* <ptr>) 21650 21651Overview: 21652""""""""" 21653 21654The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant 21655established by ``invariant.group`` metadata no longer holds, to obtain a new 21656pointer value that carries fresh invariant group information. It is an 21657experimental intrinsic, which means that its semantics might change in the 21658future. 21659 21660 21661Arguments: 21662"""""""""" 21663 21664The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer 21665to the memory. 21666 21667Semantics: 21668"""""""""" 21669 21670Returns another pointer that aliases its argument but which is considered different 21671for the purposes of ``load``/``store`` ``invariant.group`` metadata. 21672It does not read any accessible memory and the execution can be speculated. 21673 21674'``llvm.strip.invariant.group``' Intrinsic 21675^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21676 21677Syntax: 21678""""""" 21679This is an overloaded intrinsic. The memory object can belong to any address 21680space. The returned pointer must belong to the same address space as the 21681argument. 21682 21683:: 21684 21685 declare i8* @llvm.strip.invariant.group.p0i8(i8* <ptr>) 21686 21687Overview: 21688""""""""" 21689 21690The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant 21691established by ``invariant.group`` metadata no longer holds, to obtain a new pointer 21692value that does not carry the invariant information. It is an experimental 21693intrinsic, which means that its semantics might change in the future. 21694 21695 21696Arguments: 21697"""""""""" 21698 21699The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer 21700to the memory. 21701 21702Semantics: 21703"""""""""" 21704 21705Returns another pointer that aliases its argument but which has no associated 21706``invariant.group`` metadata. 21707It does not read any memory and can be speculated. 21708 21709 21710 21711.. _constrainedfp: 21712 21713Constrained Floating-Point Intrinsics 21714------------------------------------- 21715 21716These intrinsics are used to provide special handling of floating-point 21717operations when specific rounding mode or floating-point exception behavior is 21718required. By default, LLVM optimization passes assume that the rounding mode is 21719round-to-nearest and that floating-point exceptions will not be monitored. 21720Constrained FP intrinsics are used to support non-default rounding modes and 21721accurately preserve exception behavior without compromising LLVM's ability to 21722optimize FP code when the default behavior is used. 21723 21724If any FP operation in a function is constrained then they all must be 21725constrained. This is required for correct LLVM IR. Optimizations that 21726move code around can create miscompiles if mixing of constrained and normal 21727operations is done. The correct way to mix constrained and less constrained 21728operations is to use the rounding mode and exception handling metadata to 21729mark constrained intrinsics as having LLVM's default behavior. 21730 21731Each of these intrinsics corresponds to a normal floating-point operation. The 21732data arguments and the return value are the same as the corresponding FP 21733operation. 21734 21735The rounding mode argument is a metadata string specifying what 21736assumptions, if any, the optimizer can make when transforming constant 21737values. Some constrained FP intrinsics omit this argument. If required 21738by the intrinsic, this argument must be one of the following strings: 21739 21740:: 21741 21742 "round.dynamic" 21743 "round.tonearest" 21744 "round.downward" 21745 "round.upward" 21746 "round.towardzero" 21747 "round.tonearestaway" 21748 21749If this argument is "round.dynamic" optimization passes must assume that the 21750rounding mode is unknown and may change at runtime. No transformations that 21751depend on rounding mode may be performed in this case. 21752 21753The other possible values for the rounding mode argument correspond to the 21754similarly named IEEE rounding modes. If the argument is any of these values 21755optimization passes may perform transformations as long as they are consistent 21756with the specified rounding mode. 21757 21758For example, 'x-0'->'x' is not a valid transformation if the rounding mode is 21759"round.downward" or "round.dynamic" because if the value of 'x' is +0 then 21760'x-0' should evaluate to '-0' when rounding downward. However, this 21761transformation is legal for all other rounding modes. 21762 21763For values other than "round.dynamic" optimization passes may assume that the 21764actual runtime rounding mode (as defined in a target-specific manner) matches 21765the specified rounding mode, but this is not guaranteed. Using a specific 21766non-dynamic rounding mode which does not match the actual rounding mode at 21767runtime results in undefined behavior. 21768 21769The exception behavior argument is a metadata string describing the floating 21770point exception semantics that required for the intrinsic. This argument 21771must be one of the following strings: 21772 21773:: 21774 21775 "fpexcept.ignore" 21776 "fpexcept.maytrap" 21777 "fpexcept.strict" 21778 21779If this argument is "fpexcept.ignore" optimization passes may assume that the 21780exception status flags will not be read and that floating-point exceptions will 21781be masked. This allows transformations to be performed that may change the 21782exception semantics of the original code. For example, FP operations may be 21783speculatively executed in this case whereas they must not be for either of the 21784other possible values of this argument. 21785 21786If the exception behavior argument is "fpexcept.maytrap" optimization passes 21787must avoid transformations that may raise exceptions that would not have been 21788raised by the original code (such as speculatively executing FP operations), but 21789passes are not required to preserve all exceptions that are implied by the 21790original code. For example, exceptions may be potentially hidden by constant 21791folding. 21792 21793If the exception behavior argument is "fpexcept.strict" all transformations must 21794strictly preserve the floating-point exception semantics of the original code. 21795Any FP exception that would have been raised by the original code must be raised 21796by the transformed code, and the transformed code must not raise any FP 21797exceptions that would not have been raised by the original code. This is the 21798exception behavior argument that will be used if the code being compiled reads 21799the FP exception status flags, but this mode can also be used with code that 21800unmasks FP exceptions. 21801 21802The number and order of floating-point exceptions is NOT guaranteed. For 21803example, a series of FP operations that each may raise exceptions may be 21804vectorized into a single instruction that raises each unique exception a single 21805time. 21806 21807Proper :ref:`function attributes <fnattrs>` usage is required for the 21808constrained intrinsics to function correctly. 21809 21810All function *calls* done in a function that uses constrained floating 21811point intrinsics must have the ``strictfp`` attribute. 21812 21813All function *definitions* that use constrained floating point intrinsics 21814must have the ``strictfp`` attribute. 21815 21816'``llvm.experimental.constrained.fadd``' Intrinsic 21817^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21818 21819Syntax: 21820""""""" 21821 21822:: 21823 21824 declare <type> 21825 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>, 21826 metadata <rounding mode>, 21827 metadata <exception behavior>) 21828 21829Overview: 21830""""""""" 21831 21832The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its 21833two operands. 21834 21835 21836Arguments: 21837"""""""""" 21838 21839The first two arguments to the '``llvm.experimental.constrained.fadd``' 21840intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 21841of floating-point values. Both arguments must have identical types. 21842 21843The third and fourth arguments specify the rounding mode and exception 21844behavior as described above. 21845 21846Semantics: 21847"""""""""" 21848 21849The value produced is the floating-point sum of the two value operands and has 21850the same type as the operands. 21851 21852 21853'``llvm.experimental.constrained.fsub``' Intrinsic 21854^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21855 21856Syntax: 21857""""""" 21858 21859:: 21860 21861 declare <type> 21862 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>, 21863 metadata <rounding mode>, 21864 metadata <exception behavior>) 21865 21866Overview: 21867""""""""" 21868 21869The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference 21870of its two operands. 21871 21872 21873Arguments: 21874"""""""""" 21875 21876The first two arguments to the '``llvm.experimental.constrained.fsub``' 21877intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 21878of floating-point values. Both arguments must have identical types. 21879 21880The third and fourth arguments specify the rounding mode and exception 21881behavior as described above. 21882 21883Semantics: 21884"""""""""" 21885 21886The value produced is the floating-point difference of the two value operands 21887and has the same type as the operands. 21888 21889 21890'``llvm.experimental.constrained.fmul``' Intrinsic 21891^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21892 21893Syntax: 21894""""""" 21895 21896:: 21897 21898 declare <type> 21899 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>, 21900 metadata <rounding mode>, 21901 metadata <exception behavior>) 21902 21903Overview: 21904""""""""" 21905 21906The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of 21907its two operands. 21908 21909 21910Arguments: 21911"""""""""" 21912 21913The first two arguments to the '``llvm.experimental.constrained.fmul``' 21914intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 21915of floating-point values. Both arguments must have identical types. 21916 21917The third and fourth arguments specify the rounding mode and exception 21918behavior as described above. 21919 21920Semantics: 21921"""""""""" 21922 21923The value produced is the floating-point product of the two value operands and 21924has the same type as the operands. 21925 21926 21927'``llvm.experimental.constrained.fdiv``' Intrinsic 21928^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21929 21930Syntax: 21931""""""" 21932 21933:: 21934 21935 declare <type> 21936 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>, 21937 metadata <rounding mode>, 21938 metadata <exception behavior>) 21939 21940Overview: 21941""""""""" 21942 21943The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of 21944its two operands. 21945 21946 21947Arguments: 21948"""""""""" 21949 21950The first two arguments to the '``llvm.experimental.constrained.fdiv``' 21951intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 21952of floating-point values. Both arguments must have identical types. 21953 21954The third and fourth arguments specify the rounding mode and exception 21955behavior as described above. 21956 21957Semantics: 21958"""""""""" 21959 21960The value produced is the floating-point quotient of the two value operands and 21961has the same type as the operands. 21962 21963 21964'``llvm.experimental.constrained.frem``' Intrinsic 21965^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21966 21967Syntax: 21968""""""" 21969 21970:: 21971 21972 declare <type> 21973 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>, 21974 metadata <rounding mode>, 21975 metadata <exception behavior>) 21976 21977Overview: 21978""""""""" 21979 21980The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder 21981from the division of its two operands. 21982 21983 21984Arguments: 21985"""""""""" 21986 21987The first two arguments to the '``llvm.experimental.constrained.frem``' 21988intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 21989of floating-point values. Both arguments must have identical types. 21990 21991The third and fourth arguments specify the rounding mode and exception 21992behavior as described above. The rounding mode argument has no effect, since 21993the result of frem is never rounded, but the argument is included for 21994consistency with the other constrained floating-point intrinsics. 21995 21996Semantics: 21997"""""""""" 21998 21999The value produced is the floating-point remainder from the division of the two 22000value operands and has the same type as the operands. The remainder has the 22001same sign as the dividend. 22002 22003'``llvm.experimental.constrained.fma``' Intrinsic 22004^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22005 22006Syntax: 22007""""""" 22008 22009:: 22010 22011 declare <type> 22012 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>, 22013 metadata <rounding mode>, 22014 metadata <exception behavior>) 22015 22016Overview: 22017""""""""" 22018 22019The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a 22020fused-multiply-add operation on its operands. 22021 22022Arguments: 22023"""""""""" 22024 22025The first three arguments to the '``llvm.experimental.constrained.fma``' 22026intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector 22027<t_vector>` of floating-point values. All arguments must have identical types. 22028 22029The fourth and fifth arguments specify the rounding mode and exception behavior 22030as described above. 22031 22032Semantics: 22033"""""""""" 22034 22035The result produced is the product of the first two operands added to the third 22036operand computed with infinite precision, and then rounded to the target 22037precision. 22038 22039'``llvm.experimental.constrained.fptoui``' Intrinsic 22040^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22041 22042Syntax: 22043""""""" 22044 22045:: 22046 22047 declare <ty2> 22048 @llvm.experimental.constrained.fptoui(<type> <value>, 22049 metadata <exception behavior>) 22050 22051Overview: 22052""""""""" 22053 22054The '``llvm.experimental.constrained.fptoui``' intrinsic converts a 22055floating-point ``value`` to its unsigned integer equivalent of type ``ty2``. 22056 22057Arguments: 22058"""""""""" 22059 22060The first argument to the '``llvm.experimental.constrained.fptoui``' 22061intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 22062<t_vector>` of floating point values. 22063 22064The second argument specifies the exception behavior as described above. 22065 22066Semantics: 22067"""""""""" 22068 22069The result produced is an unsigned integer converted from the floating 22070point operand. The value is truncated, so it is rounded towards zero. 22071 22072'``llvm.experimental.constrained.fptosi``' Intrinsic 22073^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22074 22075Syntax: 22076""""""" 22077 22078:: 22079 22080 declare <ty2> 22081 @llvm.experimental.constrained.fptosi(<type> <value>, 22082 metadata <exception behavior>) 22083 22084Overview: 22085""""""""" 22086 22087The '``llvm.experimental.constrained.fptosi``' intrinsic converts 22088:ref:`floating-point <t_floating>` ``value`` to type ``ty2``. 22089 22090Arguments: 22091"""""""""" 22092 22093The first argument to the '``llvm.experimental.constrained.fptosi``' 22094intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 22095<t_vector>` of floating point values. 22096 22097The second argument specifies the exception behavior as described above. 22098 22099Semantics: 22100"""""""""" 22101 22102The result produced is a signed integer converted from the floating 22103point operand. The value is truncated, so it is rounded towards zero. 22104 22105'``llvm.experimental.constrained.uitofp``' Intrinsic 22106^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22107 22108Syntax: 22109""""""" 22110 22111:: 22112 22113 declare <ty2> 22114 @llvm.experimental.constrained.uitofp(<type> <value>, 22115 metadata <rounding mode>, 22116 metadata <exception behavior>) 22117 22118Overview: 22119""""""""" 22120 22121The '``llvm.experimental.constrained.uitofp``' intrinsic converts an 22122unsigned integer ``value`` to a floating-point of type ``ty2``. 22123 22124Arguments: 22125"""""""""" 22126 22127The first argument to the '``llvm.experimental.constrained.uitofp``' 22128intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector 22129<t_vector>` of integer values. 22130 22131The second and third arguments specify the rounding mode and exception 22132behavior as described above. 22133 22134Semantics: 22135"""""""""" 22136 22137An inexact floating-point exception will be raised if rounding is required. 22138Any result produced is a floating point value converted from the input 22139integer operand. 22140 22141'``llvm.experimental.constrained.sitofp``' Intrinsic 22142^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22143 22144Syntax: 22145""""""" 22146 22147:: 22148 22149 declare <ty2> 22150 @llvm.experimental.constrained.sitofp(<type> <value>, 22151 metadata <rounding mode>, 22152 metadata <exception behavior>) 22153 22154Overview: 22155""""""""" 22156 22157The '``llvm.experimental.constrained.sitofp``' intrinsic converts a 22158signed integer ``value`` to a floating-point of type ``ty2``. 22159 22160Arguments: 22161"""""""""" 22162 22163The first argument to the '``llvm.experimental.constrained.sitofp``' 22164intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector 22165<t_vector>` of integer values. 22166 22167The second and third arguments specify the rounding mode and exception 22168behavior as described above. 22169 22170Semantics: 22171"""""""""" 22172 22173An inexact floating-point exception will be raised if rounding is required. 22174Any result produced is a floating point value converted from the input 22175integer operand. 22176 22177'``llvm.experimental.constrained.fptrunc``' Intrinsic 22178^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22179 22180Syntax: 22181""""""" 22182 22183:: 22184 22185 declare <ty2> 22186 @llvm.experimental.constrained.fptrunc(<type> <value>, 22187 metadata <rounding mode>, 22188 metadata <exception behavior>) 22189 22190Overview: 22191""""""""" 22192 22193The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value`` 22194to type ``ty2``. 22195 22196Arguments: 22197"""""""""" 22198 22199The first argument to the '``llvm.experimental.constrained.fptrunc``' 22200intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 22201<t_vector>` of floating point values. This argument must be larger in size 22202than the result. 22203 22204The second and third arguments specify the rounding mode and exception 22205behavior as described above. 22206 22207Semantics: 22208"""""""""" 22209 22210The result produced is a floating point value truncated to be smaller in size 22211than the operand. 22212 22213'``llvm.experimental.constrained.fpext``' Intrinsic 22214^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22215 22216Syntax: 22217""""""" 22218 22219:: 22220 22221 declare <ty2> 22222 @llvm.experimental.constrained.fpext(<type> <value>, 22223 metadata <exception behavior>) 22224 22225Overview: 22226""""""""" 22227 22228The '``llvm.experimental.constrained.fpext``' intrinsic extends a 22229floating-point ``value`` to a larger floating-point value. 22230 22231Arguments: 22232"""""""""" 22233 22234The first argument to the '``llvm.experimental.constrained.fpext``' 22235intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 22236<t_vector>` of floating point values. This argument must be smaller in size 22237than the result. 22238 22239The second argument specifies the exception behavior as described above. 22240 22241Semantics: 22242"""""""""" 22243 22244The result produced is a floating point value extended to be larger in size 22245than the operand. All restrictions that apply to the fpext instruction also 22246apply to this intrinsic. 22247 22248'``llvm.experimental.constrained.fcmp``' and '``llvm.experimental.constrained.fcmps``' Intrinsics 22249^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22250 22251Syntax: 22252""""""" 22253 22254:: 22255 22256 declare <ty2> 22257 @llvm.experimental.constrained.fcmp(<type> <op1>, <type> <op2>, 22258 metadata <condition code>, 22259 metadata <exception behavior>) 22260 declare <ty2> 22261 @llvm.experimental.constrained.fcmps(<type> <op1>, <type> <op2>, 22262 metadata <condition code>, 22263 metadata <exception behavior>) 22264 22265Overview: 22266""""""""" 22267 22268The '``llvm.experimental.constrained.fcmp``' and 22269'``llvm.experimental.constrained.fcmps``' intrinsics return a boolean 22270value or vector of boolean values based on comparison of its operands. 22271 22272If the operands are floating-point scalars, then the result type is a 22273boolean (:ref:`i1 <t_integer>`). 22274 22275If the operands are floating-point vectors, then the result type is a 22276vector of boolean with the same number of elements as the operands being 22277compared. 22278 22279The '``llvm.experimental.constrained.fcmp``' intrinsic performs a quiet 22280comparison operation while the '``llvm.experimental.constrained.fcmps``' 22281intrinsic performs a signaling comparison operation. 22282 22283Arguments: 22284"""""""""" 22285 22286The first two arguments to the '``llvm.experimental.constrained.fcmp``' 22287and '``llvm.experimental.constrained.fcmps``' intrinsics must be 22288:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 22289of floating-point values. Both arguments must have identical types. 22290 22291The third argument is the condition code indicating the kind of comparison 22292to perform. It must be a metadata string with one of the following values: 22293 22294.. _fcmp_md_cc: 22295 22296- "``oeq``": ordered and equal 22297- "``ogt``": ordered and greater than 22298- "``oge``": ordered and greater than or equal 22299- "``olt``": ordered and less than 22300- "``ole``": ordered and less than or equal 22301- "``one``": ordered and not equal 22302- "``ord``": ordered (no nans) 22303- "``ueq``": unordered or equal 22304- "``ugt``": unordered or greater than 22305- "``uge``": unordered or greater than or equal 22306- "``ult``": unordered or less than 22307- "``ule``": unordered or less than or equal 22308- "``une``": unordered or not equal 22309- "``uno``": unordered (either nans) 22310 22311*Ordered* means that neither operand is a NAN while *unordered* means 22312that either operand may be a NAN. 22313 22314The fourth argument specifies the exception behavior as described above. 22315 22316Semantics: 22317"""""""""" 22318 22319``op1`` and ``op2`` are compared according to the condition code given 22320as the third argument. If the operands are vectors, then the 22321vectors are compared element by element. Each comparison performed 22322always yields an :ref:`i1 <t_integer>` result, as follows: 22323 22324.. _fcmp_md_cc_sem: 22325 22326- "``oeq``": yields ``true`` if both operands are not a NAN and ``op1`` 22327 is equal to ``op2``. 22328- "``ogt``": yields ``true`` if both operands are not a NAN and ``op1`` 22329 is greater than ``op2``. 22330- "``oge``": yields ``true`` if both operands are not a NAN and ``op1`` 22331 is greater than or equal to ``op2``. 22332- "``olt``": yields ``true`` if both operands are not a NAN and ``op1`` 22333 is less than ``op2``. 22334- "``ole``": yields ``true`` if both operands are not a NAN and ``op1`` 22335 is less than or equal to ``op2``. 22336- "``one``": yields ``true`` if both operands are not a NAN and ``op1`` 22337 is not equal to ``op2``. 22338- "``ord``": yields ``true`` if both operands are not a NAN. 22339- "``ueq``": yields ``true`` if either operand is a NAN or ``op1`` is 22340 equal to ``op2``. 22341- "``ugt``": yields ``true`` if either operand is a NAN or ``op1`` is 22342 greater than ``op2``. 22343- "``uge``": yields ``true`` if either operand is a NAN or ``op1`` is 22344 greater than or equal to ``op2``. 22345- "``ult``": yields ``true`` if either operand is a NAN or ``op1`` is 22346 less than ``op2``. 22347- "``ule``": yields ``true`` if either operand is a NAN or ``op1`` is 22348 less than or equal to ``op2``. 22349- "``une``": yields ``true`` if either operand is a NAN or ``op1`` is 22350 not equal to ``op2``. 22351- "``uno``": yields ``true`` if either operand is a NAN. 22352 22353The quiet comparison operation performed by 22354'``llvm.experimental.constrained.fcmp``' will only raise an exception 22355if either operand is a SNAN. The signaling comparison operation 22356performed by '``llvm.experimental.constrained.fcmps``' will raise an 22357exception if either operand is a NAN (QNAN or SNAN). Such an exception 22358does not preclude a result being produced (e.g. exception might only 22359set a flag), therefore the distinction between ordered and unordered 22360comparisons is also relevant for the 22361'``llvm.experimental.constrained.fcmps``' intrinsic. 22362 22363'``llvm.experimental.constrained.fmuladd``' Intrinsic 22364^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22365 22366Syntax: 22367""""""" 22368 22369:: 22370 22371 declare <type> 22372 @llvm.experimental.constrained.fmuladd(<type> <op1>, <type> <op2>, 22373 <type> <op3>, 22374 metadata <rounding mode>, 22375 metadata <exception behavior>) 22376 22377Overview: 22378""""""""" 22379 22380The '``llvm.experimental.constrained.fmuladd``' intrinsic represents 22381multiply-add expressions that can be fused if the code generator determines 22382that (a) the target instruction set has support for a fused operation, 22383and (b) that the fused operation is more efficient than the equivalent, 22384separate pair of mul and add instructions. 22385 22386Arguments: 22387"""""""""" 22388 22389The first three arguments to the '``llvm.experimental.constrained.fmuladd``' 22390intrinsic must be floating-point or vector of floating-point values. 22391All three arguments must have identical types. 22392 22393The fourth and fifth arguments specify the rounding mode and exception behavior 22394as described above. 22395 22396Semantics: 22397"""""""""" 22398 22399The expression: 22400 22401:: 22402 22403 %0 = call float @llvm.experimental.constrained.fmuladd.f32(%a, %b, %c, 22404 metadata <rounding mode>, 22405 metadata <exception behavior>) 22406 22407is equivalent to the expression: 22408 22409:: 22410 22411 %0 = call float @llvm.experimental.constrained.fmul.f32(%a, %b, 22412 metadata <rounding mode>, 22413 metadata <exception behavior>) 22414 %1 = call float @llvm.experimental.constrained.fadd.f32(%0, %c, 22415 metadata <rounding mode>, 22416 metadata <exception behavior>) 22417 22418except that it is unspecified whether rounding will be performed between the 22419multiplication and addition steps. Fusion is not guaranteed, even if the target 22420platform supports it. 22421If a fused multiply-add is required, the corresponding 22422:ref:`llvm.experimental.constrained.fma <int_fma>` intrinsic function should be 22423used instead. 22424This never sets errno, just as '``llvm.experimental.constrained.fma.*``'. 22425 22426Constrained libm-equivalent Intrinsics 22427-------------------------------------- 22428 22429In addition to the basic floating-point operations for which constrained 22430intrinsics are described above, there are constrained versions of various 22431operations which provide equivalent behavior to a corresponding libm function. 22432These intrinsics allow the precise behavior of these operations with respect to 22433rounding mode and exception behavior to be controlled. 22434 22435As with the basic constrained floating-point intrinsics, the rounding mode 22436and exception behavior arguments only control the behavior of the optimizer. 22437They do not change the runtime floating-point environment. 22438 22439 22440'``llvm.experimental.constrained.sqrt``' Intrinsic 22441^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22442 22443Syntax: 22444""""""" 22445 22446:: 22447 22448 declare <type> 22449 @llvm.experimental.constrained.sqrt(<type> <op1>, 22450 metadata <rounding mode>, 22451 metadata <exception behavior>) 22452 22453Overview: 22454""""""""" 22455 22456The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root 22457of the specified value, returning the same value as the libm '``sqrt``' 22458functions would, but without setting ``errno``. 22459 22460Arguments: 22461"""""""""" 22462 22463The first argument and the return type are floating-point numbers of the same 22464type. 22465 22466The second and third arguments specify the rounding mode and exception 22467behavior as described above. 22468 22469Semantics: 22470"""""""""" 22471 22472This function returns the nonnegative square root of the specified value. 22473If the value is less than negative zero, a floating-point exception occurs 22474and the return value is architecture specific. 22475 22476 22477'``llvm.experimental.constrained.pow``' Intrinsic 22478^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22479 22480Syntax: 22481""""""" 22482 22483:: 22484 22485 declare <type> 22486 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>, 22487 metadata <rounding mode>, 22488 metadata <exception behavior>) 22489 22490Overview: 22491""""""""" 22492 22493The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand 22494raised to the (positive or negative) power specified by the second operand. 22495 22496Arguments: 22497"""""""""" 22498 22499The first two arguments and the return value are floating-point numbers of the 22500same type. The second argument specifies the power to which the first argument 22501should be raised. 22502 22503The third and fourth arguments specify the rounding mode and exception 22504behavior as described above. 22505 22506Semantics: 22507"""""""""" 22508 22509This function returns the first value raised to the second power, 22510returning the same values as the libm ``pow`` functions would, and 22511handles error conditions in the same way. 22512 22513 22514'``llvm.experimental.constrained.powi``' Intrinsic 22515^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22516 22517Syntax: 22518""""""" 22519 22520:: 22521 22522 declare <type> 22523 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>, 22524 metadata <rounding mode>, 22525 metadata <exception behavior>) 22526 22527Overview: 22528""""""""" 22529 22530The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand 22531raised to the (positive or negative) power specified by the second operand. The 22532order of evaluation of multiplications is not defined. When a vector of 22533floating-point type is used, the second argument remains a scalar integer value. 22534 22535 22536Arguments: 22537"""""""""" 22538 22539The first argument and the return value are floating-point numbers of the same 22540type. The second argument is a 32-bit signed integer specifying the power to 22541which the first argument should be raised. 22542 22543The third and fourth arguments specify the rounding mode and exception 22544behavior as described above. 22545 22546Semantics: 22547"""""""""" 22548 22549This function returns the first value raised to the second power with an 22550unspecified sequence of rounding operations. 22551 22552 22553'``llvm.experimental.constrained.sin``' Intrinsic 22554^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22555 22556Syntax: 22557""""""" 22558 22559:: 22560 22561 declare <type> 22562 @llvm.experimental.constrained.sin(<type> <op1>, 22563 metadata <rounding mode>, 22564 metadata <exception behavior>) 22565 22566Overview: 22567""""""""" 22568 22569The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the 22570first operand. 22571 22572Arguments: 22573"""""""""" 22574 22575The first argument and the return type 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 sine of the specified operand, returning the 22585same values as the libm ``sin`` functions would, and handles error 22586conditions in the same way. 22587 22588 22589'``llvm.experimental.constrained.cos``' Intrinsic 22590^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22591 22592Syntax: 22593""""""" 22594 22595:: 22596 22597 declare <type> 22598 @llvm.experimental.constrained.cos(<type> <op1>, 22599 metadata <rounding mode>, 22600 metadata <exception behavior>) 22601 22602Overview: 22603""""""""" 22604 22605The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the 22606first operand. 22607 22608Arguments: 22609"""""""""" 22610 22611The first argument and the return type are floating-point numbers of the same 22612type. 22613 22614The second and third arguments specify the rounding mode and exception 22615behavior as described above. 22616 22617Semantics: 22618"""""""""" 22619 22620This function returns the cosine of the specified operand, returning the 22621same values as the libm ``cos`` functions would, and handles error 22622conditions in the same way. 22623 22624 22625'``llvm.experimental.constrained.exp``' Intrinsic 22626^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22627 22628Syntax: 22629""""""" 22630 22631:: 22632 22633 declare <type> 22634 @llvm.experimental.constrained.exp(<type> <op1>, 22635 metadata <rounding mode>, 22636 metadata <exception behavior>) 22637 22638Overview: 22639""""""""" 22640 22641The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e 22642exponential of the specified value. 22643 22644Arguments: 22645"""""""""" 22646 22647The first argument and the return value are floating-point numbers of the same 22648type. 22649 22650The second and third arguments specify the rounding mode and exception 22651behavior as described above. 22652 22653Semantics: 22654"""""""""" 22655 22656This function returns the same values as the libm ``exp`` functions 22657would, and handles error conditions in the same way. 22658 22659 22660'``llvm.experimental.constrained.exp2``' Intrinsic 22661^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22662 22663Syntax: 22664""""""" 22665 22666:: 22667 22668 declare <type> 22669 @llvm.experimental.constrained.exp2(<type> <op1>, 22670 metadata <rounding mode>, 22671 metadata <exception behavior>) 22672 22673Overview: 22674""""""""" 22675 22676The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2 22677exponential of the specified value. 22678 22679 22680Arguments: 22681"""""""""" 22682 22683The first argument and the return value are floating-point numbers of the same 22684type. 22685 22686The second and third arguments specify the rounding mode and exception 22687behavior as described above. 22688 22689Semantics: 22690"""""""""" 22691 22692This function returns the same values as the libm ``exp2`` functions 22693would, and handles error conditions in the same way. 22694 22695 22696'``llvm.experimental.constrained.log``' Intrinsic 22697^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22698 22699Syntax: 22700""""""" 22701 22702:: 22703 22704 declare <type> 22705 @llvm.experimental.constrained.log(<type> <op1>, 22706 metadata <rounding mode>, 22707 metadata <exception behavior>) 22708 22709Overview: 22710""""""""" 22711 22712The '``llvm.experimental.constrained.log``' intrinsic computes the base-e 22713logarithm of the specified value. 22714 22715Arguments: 22716"""""""""" 22717 22718The first argument and the return value are floating-point numbers of the same 22719type. 22720 22721The second and third arguments specify the rounding mode and exception 22722behavior as described above. 22723 22724 22725Semantics: 22726"""""""""" 22727 22728This function returns the same values as the libm ``log`` functions 22729would, and handles error conditions in the same way. 22730 22731 22732'``llvm.experimental.constrained.log10``' Intrinsic 22733^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22734 22735Syntax: 22736""""""" 22737 22738:: 22739 22740 declare <type> 22741 @llvm.experimental.constrained.log10(<type> <op1>, 22742 metadata <rounding mode>, 22743 metadata <exception behavior>) 22744 22745Overview: 22746""""""""" 22747 22748The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10 22749logarithm of the specified value. 22750 22751Arguments: 22752"""""""""" 22753 22754The first argument and the return value are floating-point numbers of the same 22755type. 22756 22757The second and third arguments specify the rounding mode and exception 22758behavior as described above. 22759 22760Semantics: 22761"""""""""" 22762 22763This function returns the same values as the libm ``log10`` functions 22764would, and handles error conditions in the same way. 22765 22766 22767'``llvm.experimental.constrained.log2``' Intrinsic 22768^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22769 22770Syntax: 22771""""""" 22772 22773:: 22774 22775 declare <type> 22776 @llvm.experimental.constrained.log2(<type> <op1>, 22777 metadata <rounding mode>, 22778 metadata <exception behavior>) 22779 22780Overview: 22781""""""""" 22782 22783The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2 22784logarithm of the specified value. 22785 22786Arguments: 22787"""""""""" 22788 22789The first argument and the return value are floating-point numbers of the same 22790type. 22791 22792The second and third arguments specify the rounding mode and exception 22793behavior as described above. 22794 22795Semantics: 22796"""""""""" 22797 22798This function returns the same values as the libm ``log2`` functions 22799would, and handles error conditions in the same way. 22800 22801 22802'``llvm.experimental.constrained.rint``' Intrinsic 22803^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22804 22805Syntax: 22806""""""" 22807 22808:: 22809 22810 declare <type> 22811 @llvm.experimental.constrained.rint(<type> <op1>, 22812 metadata <rounding mode>, 22813 metadata <exception behavior>) 22814 22815Overview: 22816""""""""" 22817 22818The '``llvm.experimental.constrained.rint``' intrinsic returns the first 22819operand rounded to the nearest integer. It may raise an inexact floating-point 22820exception if the operand is not an integer. 22821 22822Arguments: 22823"""""""""" 22824 22825The first argument and the return value are floating-point numbers of the same 22826type. 22827 22828The second and third arguments specify the rounding mode and exception 22829behavior as described above. 22830 22831Semantics: 22832"""""""""" 22833 22834This function returns the same values as the libm ``rint`` functions 22835would, and handles error conditions in the same way. The rounding mode is 22836described, not determined, by the rounding mode argument. The actual rounding 22837mode is determined by the runtime floating-point environment. The rounding 22838mode argument is only intended as information to the compiler. 22839 22840 22841'``llvm.experimental.constrained.lrint``' Intrinsic 22842^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22843 22844Syntax: 22845""""""" 22846 22847:: 22848 22849 declare <inttype> 22850 @llvm.experimental.constrained.lrint(<fptype> <op1>, 22851 metadata <rounding mode>, 22852 metadata <exception behavior>) 22853 22854Overview: 22855""""""""" 22856 22857The '``llvm.experimental.constrained.lrint``' intrinsic returns the first 22858operand rounded to the nearest integer. An inexact floating-point exception 22859will be raised if the operand is not an integer. An invalid exception is 22860raised if the result is too large to fit into a supported integer type, 22861and in this case the result is undefined. 22862 22863Arguments: 22864"""""""""" 22865 22866The first argument is a floating-point number. The return value is an 22867integer type. Not all types are supported on all targets. The supported 22868types are the same as the ``llvm.lrint`` intrinsic and the ``lrint`` 22869libm functions. 22870 22871The second and third arguments specify the rounding mode and exception 22872behavior as described above. 22873 22874Semantics: 22875"""""""""" 22876 22877This function returns the same values as the libm ``lrint`` functions 22878would, and handles error conditions in the same way. 22879 22880The rounding mode is described, not determined, by the rounding mode 22881argument. The actual rounding mode is determined by the runtime floating-point 22882environment. The rounding mode argument is only intended as information 22883to the compiler. 22884 22885If the runtime floating-point environment is using the default rounding mode 22886then the results will be the same as the llvm.lrint intrinsic. 22887 22888 22889'``llvm.experimental.constrained.llrint``' Intrinsic 22890^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22891 22892Syntax: 22893""""""" 22894 22895:: 22896 22897 declare <inttype> 22898 @llvm.experimental.constrained.llrint(<fptype> <op1>, 22899 metadata <rounding mode>, 22900 metadata <exception behavior>) 22901 22902Overview: 22903""""""""" 22904 22905The '``llvm.experimental.constrained.llrint``' intrinsic returns the first 22906operand rounded to the nearest integer. An inexact floating-point exception 22907will be raised if the operand is not an integer. An invalid exception is 22908raised if the result is too large to fit into a supported integer type, 22909and in this case the result is undefined. 22910 22911Arguments: 22912"""""""""" 22913 22914The first argument is a floating-point number. The return value is an 22915integer type. Not all types are supported on all targets. The supported 22916types are the same as the ``llvm.llrint`` intrinsic and the ``llrint`` 22917libm functions. 22918 22919The second and third arguments specify the rounding mode and exception 22920behavior as described above. 22921 22922Semantics: 22923"""""""""" 22924 22925This function returns the same values as the libm ``llrint`` functions 22926would, and handles error conditions in the same way. 22927 22928The rounding mode is described, not determined, by the rounding mode 22929argument. The actual rounding mode is determined by the runtime floating-point 22930environment. The rounding mode argument is only intended as information 22931to the compiler. 22932 22933If the runtime floating-point environment is using the default rounding mode 22934then the results will be the same as the llvm.llrint intrinsic. 22935 22936 22937'``llvm.experimental.constrained.nearbyint``' Intrinsic 22938^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22939 22940Syntax: 22941""""""" 22942 22943:: 22944 22945 declare <type> 22946 @llvm.experimental.constrained.nearbyint(<type> <op1>, 22947 metadata <rounding mode>, 22948 metadata <exception behavior>) 22949 22950Overview: 22951""""""""" 22952 22953The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first 22954operand rounded to the nearest integer. It will not raise an inexact 22955floating-point exception if the operand is not an integer. 22956 22957 22958Arguments: 22959"""""""""" 22960 22961The first argument and the return value are floating-point numbers of the same 22962type. 22963 22964The second and third arguments specify the rounding mode and exception 22965behavior as described above. 22966 22967Semantics: 22968"""""""""" 22969 22970This function returns the same values as the libm ``nearbyint`` functions 22971would, and handles error conditions in the same way. The rounding mode is 22972described, not determined, by the rounding mode argument. The actual rounding 22973mode is determined by the runtime floating-point environment. The rounding 22974mode argument is only intended as information to the compiler. 22975 22976 22977'``llvm.experimental.constrained.maxnum``' Intrinsic 22978^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22979 22980Syntax: 22981""""""" 22982 22983:: 22984 22985 declare <type> 22986 @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2> 22987 metadata <exception behavior>) 22988 22989Overview: 22990""""""""" 22991 22992The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum 22993of the two arguments. 22994 22995Arguments: 22996"""""""""" 22997 22998The first two arguments and the return value are floating-point numbers 22999of the same type. 23000 23001The third argument specifies the exception behavior as described above. 23002 23003Semantics: 23004"""""""""" 23005 23006This function follows the IEEE-754 semantics for maxNum. 23007 23008 23009'``llvm.experimental.constrained.minnum``' Intrinsic 23010^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23011 23012Syntax: 23013""""""" 23014 23015:: 23016 23017 declare <type> 23018 @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2> 23019 metadata <exception behavior>) 23020 23021Overview: 23022""""""""" 23023 23024The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum 23025of the two arguments. 23026 23027Arguments: 23028"""""""""" 23029 23030The first two arguments and the return value are floating-point numbers 23031of the same type. 23032 23033The third argument specifies the exception behavior as described above. 23034 23035Semantics: 23036"""""""""" 23037 23038This function follows the IEEE-754 semantics for minNum. 23039 23040 23041'``llvm.experimental.constrained.maximum``' Intrinsic 23042^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23043 23044Syntax: 23045""""""" 23046 23047:: 23048 23049 declare <type> 23050 @llvm.experimental.constrained.maximum(<type> <op1>, <type> <op2> 23051 metadata <exception behavior>) 23052 23053Overview: 23054""""""""" 23055 23056The '``llvm.experimental.constrained.maximum``' intrinsic returns the maximum 23057of the two arguments, propagating NaNs and treating -0.0 as less than +0.0. 23058 23059Arguments: 23060"""""""""" 23061 23062The first two arguments and the return value are floating-point numbers 23063of the same type. 23064 23065The third argument specifies the exception behavior as described above. 23066 23067Semantics: 23068"""""""""" 23069 23070This function follows semantics specified in the draft of IEEE 754-2018. 23071 23072 23073'``llvm.experimental.constrained.minimum``' Intrinsic 23074^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23075 23076Syntax: 23077""""""" 23078 23079:: 23080 23081 declare <type> 23082 @llvm.experimental.constrained.minimum(<type> <op1>, <type> <op2> 23083 metadata <exception behavior>) 23084 23085Overview: 23086""""""""" 23087 23088The '``llvm.experimental.constrained.minimum``' intrinsic returns the minimum 23089of the two arguments, propagating NaNs and treating -0.0 as less than +0.0. 23090 23091Arguments: 23092"""""""""" 23093 23094The first two arguments and the return value are floating-point numbers 23095of the same type. 23096 23097The third argument specifies the exception behavior as described above. 23098 23099Semantics: 23100"""""""""" 23101 23102This function follows semantics specified in the draft of IEEE 754-2018. 23103 23104 23105'``llvm.experimental.constrained.ceil``' Intrinsic 23106^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23107 23108Syntax: 23109""""""" 23110 23111:: 23112 23113 declare <type> 23114 @llvm.experimental.constrained.ceil(<type> <op1>, 23115 metadata <exception behavior>) 23116 23117Overview: 23118""""""""" 23119 23120The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the 23121first operand. 23122 23123Arguments: 23124"""""""""" 23125 23126The first argument and the return value are floating-point numbers of the same 23127type. 23128 23129The second argument specifies the exception behavior as described above. 23130 23131Semantics: 23132"""""""""" 23133 23134This function returns the same values as the libm ``ceil`` functions 23135would and handles error conditions in the same way. 23136 23137 23138'``llvm.experimental.constrained.floor``' Intrinsic 23139^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23140 23141Syntax: 23142""""""" 23143 23144:: 23145 23146 declare <type> 23147 @llvm.experimental.constrained.floor(<type> <op1>, 23148 metadata <exception behavior>) 23149 23150Overview: 23151""""""""" 23152 23153The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the 23154first operand. 23155 23156Arguments: 23157"""""""""" 23158 23159The first argument and the return value are floating-point numbers of the same 23160type. 23161 23162The second argument specifies the exception behavior as described above. 23163 23164Semantics: 23165"""""""""" 23166 23167This function returns the same values as the libm ``floor`` functions 23168would and handles error conditions in the same way. 23169 23170 23171'``llvm.experimental.constrained.round``' Intrinsic 23172^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23173 23174Syntax: 23175""""""" 23176 23177:: 23178 23179 declare <type> 23180 @llvm.experimental.constrained.round(<type> <op1>, 23181 metadata <exception behavior>) 23182 23183Overview: 23184""""""""" 23185 23186The '``llvm.experimental.constrained.round``' intrinsic returns the first 23187operand rounded to the nearest integer. 23188 23189Arguments: 23190"""""""""" 23191 23192The first argument and the return value are floating-point numbers of the same 23193type. 23194 23195The second argument specifies the exception behavior as described above. 23196 23197Semantics: 23198"""""""""" 23199 23200This function returns the same values as the libm ``round`` functions 23201would and handles error conditions in the same way. 23202 23203 23204'``llvm.experimental.constrained.roundeven``' Intrinsic 23205^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23206 23207Syntax: 23208""""""" 23209 23210:: 23211 23212 declare <type> 23213 @llvm.experimental.constrained.roundeven(<type> <op1>, 23214 metadata <exception behavior>) 23215 23216Overview: 23217""""""""" 23218 23219The '``llvm.experimental.constrained.roundeven``' intrinsic returns the first 23220operand rounded to the nearest integer in floating-point format, rounding 23221halfway cases to even (that is, to the nearest value that is an even integer), 23222regardless of the current rounding direction. 23223 23224Arguments: 23225"""""""""" 23226 23227The first argument and the return value are floating-point numbers of the same 23228type. 23229 23230The second argument specifies the exception behavior as described above. 23231 23232Semantics: 23233"""""""""" 23234 23235This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It 23236also behaves in the same way as C standard function ``roundeven`` and can signal 23237the invalid operation exception for a SNAN operand. 23238 23239 23240'``llvm.experimental.constrained.lround``' Intrinsic 23241^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23242 23243Syntax: 23244""""""" 23245 23246:: 23247 23248 declare <inttype> 23249 @llvm.experimental.constrained.lround(<fptype> <op1>, 23250 metadata <exception behavior>) 23251 23252Overview: 23253""""""""" 23254 23255The '``llvm.experimental.constrained.lround``' intrinsic returns the first 23256operand rounded to the nearest integer with ties away from zero. It will 23257raise an inexact floating-point exception if the operand is not an integer. 23258An invalid exception is raised if the result is too large to fit into a 23259supported integer type, and in this case the result is undefined. 23260 23261Arguments: 23262"""""""""" 23263 23264The first argument is a floating-point number. The return value is an 23265integer type. Not all types are supported on all targets. The supported 23266types are the same as the ``llvm.lround`` intrinsic and the ``lround`` 23267libm functions. 23268 23269The second argument specifies the exception behavior as described above. 23270 23271Semantics: 23272"""""""""" 23273 23274This function returns the same values as the libm ``lround`` functions 23275would and handles error conditions in the same way. 23276 23277 23278'``llvm.experimental.constrained.llround``' Intrinsic 23279^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23280 23281Syntax: 23282""""""" 23283 23284:: 23285 23286 declare <inttype> 23287 @llvm.experimental.constrained.llround(<fptype> <op1>, 23288 metadata <exception behavior>) 23289 23290Overview: 23291""""""""" 23292 23293The '``llvm.experimental.constrained.llround``' intrinsic returns the first 23294operand rounded to the nearest integer with ties away from zero. It will 23295raise an inexact floating-point exception if the operand is not an integer. 23296An invalid exception is raised if the result is too large to fit into a 23297supported integer type, and in this case the result is undefined. 23298 23299Arguments: 23300"""""""""" 23301 23302The first argument is a floating-point number. The return value is an 23303integer type. Not all types are supported on all targets. The supported 23304types are the same as the ``llvm.llround`` intrinsic and the ``llround`` 23305libm functions. 23306 23307The second argument specifies the exception behavior as described above. 23308 23309Semantics: 23310"""""""""" 23311 23312This function returns the same values as the libm ``llround`` functions 23313would and handles error conditions in the same way. 23314 23315 23316'``llvm.experimental.constrained.trunc``' Intrinsic 23317^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23318 23319Syntax: 23320""""""" 23321 23322:: 23323 23324 declare <type> 23325 @llvm.experimental.constrained.trunc(<type> <op1>, 23326 metadata <exception behavior>) 23327 23328Overview: 23329""""""""" 23330 23331The '``llvm.experimental.constrained.trunc``' intrinsic returns the first 23332operand rounded to the nearest integer not larger in magnitude than the 23333operand. 23334 23335Arguments: 23336"""""""""" 23337 23338The first argument and the return value are floating-point numbers of the same 23339type. 23340 23341The second argument specifies the exception behavior as described above. 23342 23343Semantics: 23344"""""""""" 23345 23346This function returns the same values as the libm ``trunc`` functions 23347would and handles error conditions in the same way. 23348 23349.. _int_experimental_noalias_scope_decl: 23350 23351'``llvm.experimental.noalias.scope.decl``' Intrinsic 23352^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23353 23354Syntax: 23355""""""" 23356 23357 23358:: 23359 23360 declare void @llvm.experimental.noalias.scope.decl(metadata !id.scope.list) 23361 23362Overview: 23363""""""""" 23364 23365The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a 23366noalias scope is declared. When the intrinsic is duplicated, a decision must 23367also be made about the scope: depending on the reason of the duplication, 23368the scope might need to be duplicated as well. 23369 23370 23371Arguments: 23372"""""""""" 23373 23374The ``!id.scope.list`` argument is metadata that is a list of ``noalias`` 23375metadata references. The format is identical to that required for ``noalias`` 23376metadata. This list must have exactly one element. 23377 23378Semantics: 23379"""""""""" 23380 23381The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a 23382noalias scope is declared. When the intrinsic is duplicated, a decision must 23383also be made about the scope: depending on the reason of the duplication, 23384the scope might need to be duplicated as well. 23385 23386For example, when the intrinsic is used inside a loop body, and that loop is 23387unrolled, the associated noalias scope must also be duplicated. Otherwise, the 23388noalias property it signifies would spill across loop iterations, whereas it 23389was only valid within a single iteration. 23390 23391.. code-block:: llvm 23392 23393 ; This examples shows two possible positions for noalias.decl and how they impact the semantics: 23394 ; If it is outside the loop (Version 1), then %a and %b are noalias across *all* iterations. 23395 ; If it is inside the loop (Version 2), then %a and %b are noalias only within *one* iteration. 23396 declare void @decl_in_loop(i8* %a.base, i8* %b.base) { 23397 entry: 23398 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 1: noalias decl outside loop 23399 br label %loop 23400 23401 loop: 23402 %a = phi i8* [ %a.base, %entry ], [ %a.inc, %loop ] 23403 %b = phi i8* [ %b.base, %entry ], [ %b.inc, %loop ] 23404 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 2: noalias decl inside loop 23405 %val = load i8, i8* %a, !alias.scope !2 23406 store i8 %val, i8* %b, !noalias !2 23407 %a.inc = getelementptr inbounds i8, i8* %a, i64 1 23408 %b.inc = getelementptr inbounds i8, i8* %b, i64 1 23409 %cond = call i1 @cond() 23410 br i1 %cond, label %loop, label %exit 23411 23412 exit: 23413 ret void 23414 } 23415 23416 !0 = !{!0} ; domain 23417 !1 = !{!1, !0} ; scope 23418 !2 = !{!1} ; scope list 23419 23420Multiple calls to `@llvm.experimental.noalias.scope.decl` for the same scope 23421are possible, but one should never dominate another. Violations are pointed out 23422by the verifier as they indicate a problem in either a transformation pass or 23423the input. 23424 23425 23426Floating Point Environment Manipulation intrinsics 23427-------------------------------------------------- 23428 23429These functions read or write floating point environment, such as rounding 23430mode or state of floating point exceptions. Altering the floating point 23431environment requires special care. See :ref:`Floating Point Environment <floatenv>`. 23432 23433'``llvm.flt.rounds``' Intrinsic 23434^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23435 23436Syntax: 23437""""""" 23438 23439:: 23440 23441 declare i32 @llvm.flt.rounds() 23442 23443Overview: 23444""""""""" 23445 23446The '``llvm.flt.rounds``' intrinsic reads the current rounding mode. 23447 23448Semantics: 23449"""""""""" 23450 23451The '``llvm.flt.rounds``' intrinsic returns the current rounding mode. 23452Encoding of the returned values is same as the result of ``FLT_ROUNDS``, 23453specified by C standard: 23454 23455:: 23456 23457 0 - toward zero 23458 1 - to nearest, ties to even 23459 2 - toward positive infinity 23460 3 - toward negative infinity 23461 4 - to nearest, ties away from zero 23462 23463Other values may be used to represent additional rounding modes, supported by a 23464target. These values are target-specific. 23465 23466 23467'``llvm.set.rounding``' Intrinsic 23468^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23469 23470Syntax: 23471""""""" 23472 23473:: 23474 23475 declare void @llvm.set.rounding(i32 <val>) 23476 23477Overview: 23478""""""""" 23479 23480The '``llvm.set.rounding``' intrinsic sets current rounding mode. 23481 23482Arguments: 23483"""""""""" 23484 23485The argument is the required rounding mode. Encoding of rounding mode is 23486the same as used by '``llvm.flt.rounds``'. 23487 23488Semantics: 23489"""""""""" 23490 23491The '``llvm.set.rounding``' intrinsic sets the current rounding mode. It is 23492similar to C library function 'fesetround', however this intrinsic does not 23493return any value and uses platform-independent representation of IEEE rounding 23494modes. 23495 23496 23497Floating-Point Test Intrinsics 23498------------------------------ 23499 23500These functions get properties of floating-point values. 23501 23502 23503'``llvm.is.fpclass``' Intrinsic 23504^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23505 23506Syntax: 23507""""""" 23508 23509:: 23510 23511 declare i1 @llvm.is.fpclass(<fptype> <op>, i32 <test>) 23512 declare <N x i1> @llvm.is.fpclass(<vector-fptype> <op>, i32 <test>) 23513 23514Overview: 23515""""""""" 23516 23517The '``llvm.is.fpclass``' intrinsic returns a boolean value or vector of boolean 23518values depending on whether the first argument satisfies the test specified by 23519the second argument. 23520 23521If the first argument is a floating-point scalar, then the result type is a 23522boolean (:ref:`i1 <t_integer>`). 23523 23524If the first argument is a floating-point vector, then the result type is a 23525vector of boolean with the same number of elements as the first argument. 23526 23527Arguments: 23528"""""""""" 23529 23530The first argument to the '``llvm.is.fpclass``' intrinsic must be 23531:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 23532of floating-point values. 23533 23534The second argument specifies, which tests to perform. It must be a compile-time 23535integer constant, each bit in which specifies floating-point class: 23536 23537+-------+----------------------+ 23538| Bit # | floating-point class | 23539+=======+======================+ 23540| 0 | Signaling NaN | 23541+-------+----------------------+ 23542| 1 | Quiet NaN | 23543+-------+----------------------+ 23544| 2 | Negative infinity | 23545+-------+----------------------+ 23546| 3 | Negative normal | 23547+-------+----------------------+ 23548| 4 | Negative subnormal | 23549+-------+----------------------+ 23550| 5 | Negative zero | 23551+-------+----------------------+ 23552| 6 | Positive zero | 23553+-------+----------------------+ 23554| 7 | Positive subnormal | 23555+-------+----------------------+ 23556| 8 | Positive normal | 23557+-------+----------------------+ 23558| 9 | Positive infinity | 23559+-------+----------------------+ 23560 23561Semantics: 23562"""""""""" 23563 23564The function checks if ``op`` belongs to any of the floating-point classes 23565specified by ``test``. If ``op`` is a vector, then the check is made element by 23566element. Each check yields an :ref:`i1 <t_integer>` result, which is ``true``, 23567if the element value satisfies the specified test. The argument ``test`` is a 23568bit mask where each bit specifies floating-point class to test. For example, the 23569value 0x108 makes test for normal value, - bits 3 and 8 in it are set, which 23570means that the function returns ``true`` if ``op`` is a positive or negative 23571normal value. The function never raises floating-point exceptions. 23572 23573 23574General Intrinsics 23575------------------ 23576 23577This class of intrinsics is designed to be generic and has no specific 23578purpose. 23579 23580'``llvm.var.annotation``' Intrinsic 23581^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23582 23583Syntax: 23584""""""" 23585 23586:: 23587 23588 declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>) 23589 23590Overview: 23591""""""""" 23592 23593The '``llvm.var.annotation``' intrinsic. 23594 23595Arguments: 23596"""""""""" 23597 23598The first argument is a pointer to a value, the second is a pointer to a 23599global string, the third is a pointer to a global string which is the 23600source file name, and the last argument is the line number. 23601 23602Semantics: 23603"""""""""" 23604 23605This intrinsic allows annotation of local variables with arbitrary 23606strings. This can be useful for special purpose optimizations that want 23607to look for these annotations. These have no other defined use; they are 23608ignored by code generation and optimization. 23609 23610'``llvm.ptr.annotation.*``' Intrinsic 23611^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23612 23613Syntax: 23614""""""" 23615 23616This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a 23617pointer to an integer of any width. *NOTE* you must specify an address space for 23618the pointer. The identifier for the default address space is the integer 23619'``0``'. 23620 23621:: 23622 23623 declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>) 23624 declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>) 23625 declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>) 23626 declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>) 23627 declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>) 23628 23629Overview: 23630""""""""" 23631 23632The '``llvm.ptr.annotation``' intrinsic. 23633 23634Arguments: 23635"""""""""" 23636 23637The first argument is a pointer to an integer value of arbitrary bitwidth 23638(result of some expression), the second is a pointer to a global string, the 23639third is a pointer to a global string which is the source file name, and the 23640last argument is the line number. It returns the value of the first argument. 23641 23642Semantics: 23643"""""""""" 23644 23645This intrinsic allows annotation of a pointer to an integer with arbitrary 23646strings. This can be useful for special purpose optimizations that want to look 23647for these annotations. These have no other defined use; transformations preserve 23648annotations on a best-effort basis but are allowed to replace the intrinsic with 23649its first argument without breaking semantics and the intrinsic is completely 23650dropped during instruction selection. 23651 23652'``llvm.annotation.*``' Intrinsic 23653^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23654 23655Syntax: 23656""""""" 23657 23658This is an overloaded intrinsic. You can use '``llvm.annotation``' on 23659any integer bit width. 23660 23661:: 23662 23663 declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>) 23664 declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>) 23665 declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>) 23666 declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>) 23667 declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>) 23668 23669Overview: 23670""""""""" 23671 23672The '``llvm.annotation``' intrinsic. 23673 23674Arguments: 23675"""""""""" 23676 23677The first argument is an integer value (result of some expression), the 23678second is a pointer to a global string, the third is a pointer to a 23679global string which is the source file name, and the last argument is 23680the line number. It returns the value of the first argument. 23681 23682Semantics: 23683"""""""""" 23684 23685This intrinsic allows annotations to be put on arbitrary expressions with 23686arbitrary strings. This can be useful for special purpose optimizations that 23687want to look for these annotations. These have no other defined use; 23688transformations preserve annotations on a best-effort basis but are allowed to 23689replace the intrinsic with its first argument without breaking semantics and the 23690intrinsic is completely dropped during instruction selection. 23691 23692'``llvm.codeview.annotation``' Intrinsic 23693^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23694 23695Syntax: 23696""""""" 23697 23698This annotation emits a label at its program point and an associated 23699``S_ANNOTATION`` codeview record with some additional string metadata. This is 23700used to implement MSVC's ``__annotation`` intrinsic. It is marked 23701``noduplicate``, so calls to this intrinsic prevent inlining and should be 23702considered expensive. 23703 23704:: 23705 23706 declare void @llvm.codeview.annotation(metadata) 23707 23708Arguments: 23709"""""""""" 23710 23711The argument should be an MDTuple containing any number of MDStrings. 23712 23713'``llvm.trap``' Intrinsic 23714^^^^^^^^^^^^^^^^^^^^^^^^^ 23715 23716Syntax: 23717""""""" 23718 23719:: 23720 23721 declare void @llvm.trap() cold noreturn nounwind 23722 23723Overview: 23724""""""""" 23725 23726The '``llvm.trap``' intrinsic. 23727 23728Arguments: 23729"""""""""" 23730 23731None. 23732 23733Semantics: 23734"""""""""" 23735 23736This intrinsic is lowered to the target dependent trap instruction. If 23737the target does not have a trap instruction, this intrinsic will be 23738lowered to a call of the ``abort()`` function. 23739 23740'``llvm.debugtrap``' Intrinsic 23741^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23742 23743Syntax: 23744""""""" 23745 23746:: 23747 23748 declare void @llvm.debugtrap() nounwind 23749 23750Overview: 23751""""""""" 23752 23753The '``llvm.debugtrap``' intrinsic. 23754 23755Arguments: 23756"""""""""" 23757 23758None. 23759 23760Semantics: 23761"""""""""" 23762 23763This intrinsic is lowered to code which is intended to cause an 23764execution trap with the intention of requesting the attention of a 23765debugger. 23766 23767'``llvm.ubsantrap``' Intrinsic 23768^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23769 23770Syntax: 23771""""""" 23772 23773:: 23774 23775 declare void @llvm.ubsantrap(i8 immarg) cold noreturn nounwind 23776 23777Overview: 23778""""""""" 23779 23780The '``llvm.ubsantrap``' intrinsic. 23781 23782Arguments: 23783"""""""""" 23784 23785An integer describing the kind of failure detected. 23786 23787Semantics: 23788"""""""""" 23789 23790This intrinsic is lowered to code which is intended to cause an execution trap, 23791embedding the argument into encoding of that trap somehow to discriminate 23792crashes if possible. 23793 23794Equivalent to ``@llvm.trap`` for targets that do not support this behaviour. 23795 23796'``llvm.stackprotector``' Intrinsic 23797^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23798 23799Syntax: 23800""""""" 23801 23802:: 23803 23804 declare void @llvm.stackprotector(i8* <guard>, i8** <slot>) 23805 23806Overview: 23807""""""""" 23808 23809The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it 23810onto the stack at ``slot``. The stack slot is adjusted to ensure that it 23811is placed on the stack before local variables. 23812 23813Arguments: 23814"""""""""" 23815 23816The ``llvm.stackprotector`` intrinsic requires two pointer arguments. 23817The first argument is the value loaded from the stack guard 23818``@__stack_chk_guard``. The second variable is an ``alloca`` that has 23819enough space to hold the value of the guard. 23820 23821Semantics: 23822"""""""""" 23823 23824This intrinsic causes the prologue/epilogue inserter to force the position of 23825the ``AllocaInst`` stack slot to be before local variables on the stack. This is 23826to ensure that if a local variable on the stack is overwritten, it will destroy 23827the value of the guard. When the function exits, the guard on the stack is 23828checked against the original guard by ``llvm.stackprotectorcheck``. If they are 23829different, then ``llvm.stackprotectorcheck`` causes the program to abort by 23830calling the ``__stack_chk_fail()`` function. 23831 23832'``llvm.stackguard``' Intrinsic 23833^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23834 23835Syntax: 23836""""""" 23837 23838:: 23839 23840 declare i8* @llvm.stackguard() 23841 23842Overview: 23843""""""""" 23844 23845The ``llvm.stackguard`` intrinsic returns the system stack guard value. 23846 23847It should not be generated by frontends, since it is only for internal usage. 23848The reason why we create this intrinsic is that we still support IR form Stack 23849Protector in FastISel. 23850 23851Arguments: 23852"""""""""" 23853 23854None. 23855 23856Semantics: 23857"""""""""" 23858 23859On some platforms, the value returned by this intrinsic remains unchanged 23860between loads in the same thread. On other platforms, it returns the same 23861global variable value, if any, e.g. ``@__stack_chk_guard``. 23862 23863Currently some platforms have IR-level customized stack guard loading (e.g. 23864X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be 23865in the future. 23866 23867'``llvm.objectsize``' Intrinsic 23868^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23869 23870Syntax: 23871""""""" 23872 23873:: 23874 23875 declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>) 23876 declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>) 23877 23878Overview: 23879""""""""" 23880 23881The ``llvm.objectsize`` intrinsic is designed to provide information to the 23882optimizer to determine whether a) an operation (like memcpy) will overflow a 23883buffer that corresponds to an object, or b) that a runtime check for overflow 23884isn't necessary. An object in this context means an allocation of a specific 23885class, structure, array, or other object. 23886 23887Arguments: 23888"""""""""" 23889 23890The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a 23891pointer to or into the ``object``. The second argument determines whether 23892``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is 23893unknown. The third argument controls how ``llvm.objectsize`` acts when ``null`` 23894in address space 0 is used as its pointer argument. If it's ``false``, 23895``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if 23896the ``null`` is in a non-zero address space or if ``true`` is given for the 23897third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth 23898argument to ``llvm.objectsize`` determines if the value should be evaluated at 23899runtime. 23900 23901The second, third, and fourth arguments only accept constants. 23902 23903Semantics: 23904"""""""""" 23905 23906The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of 23907the object concerned. If the size cannot be determined, ``llvm.objectsize`` 23908returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument). 23909 23910'``llvm.expect``' Intrinsic 23911^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23912 23913Syntax: 23914""""""" 23915 23916This is an overloaded intrinsic. You can use ``llvm.expect`` on any 23917integer bit width. 23918 23919:: 23920 23921 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>) 23922 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>) 23923 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>) 23924 23925Overview: 23926""""""""" 23927 23928The ``llvm.expect`` intrinsic provides information about expected (the 23929most probable) value of ``val``, which can be used by optimizers. 23930 23931Arguments: 23932"""""""""" 23933 23934The ``llvm.expect`` intrinsic takes two arguments. The first argument is 23935a value. The second argument is an expected value. 23936 23937Semantics: 23938"""""""""" 23939 23940This intrinsic is lowered to the ``val``. 23941 23942'``llvm.expect.with.probability``' Intrinsic 23943^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23944 23945Syntax: 23946""""""" 23947 23948This intrinsic is similar to ``llvm.expect``. This is an overloaded intrinsic. 23949You can use ``llvm.expect.with.probability`` on any integer bit width. 23950 23951:: 23952 23953 declare i1 @llvm.expect.with.probability.i1(i1 <val>, i1 <expected_val>, double <prob>) 23954 declare i32 @llvm.expect.with.probability.i32(i32 <val>, i32 <expected_val>, double <prob>) 23955 declare i64 @llvm.expect.with.probability.i64(i64 <val>, i64 <expected_val>, double <prob>) 23956 23957Overview: 23958""""""""" 23959 23960The ``llvm.expect.with.probability`` intrinsic provides information about 23961expected value of ``val`` with probability(or confidence) ``prob``, which can 23962be used by optimizers. 23963 23964Arguments: 23965"""""""""" 23966 23967The ``llvm.expect.with.probability`` intrinsic takes three arguments. The first 23968argument is a value. The second argument is an expected value. The third 23969argument is a probability. 23970 23971Semantics: 23972"""""""""" 23973 23974This intrinsic is lowered to the ``val``. 23975 23976.. _int_assume: 23977 23978'``llvm.assume``' Intrinsic 23979^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23980 23981Syntax: 23982""""""" 23983 23984:: 23985 23986 declare void @llvm.assume(i1 %cond) 23987 23988Overview: 23989""""""""" 23990 23991The ``llvm.assume`` allows the optimizer to assume that the provided 23992condition is true. This information can then be used in simplifying other parts 23993of the code. 23994 23995More complex assumptions can be encoded as 23996:ref:`assume operand bundles <assume_opbundles>`. 23997 23998Arguments: 23999"""""""""" 24000 24001The argument of the call is the condition which the optimizer may assume is 24002always true. 24003 24004Semantics: 24005"""""""""" 24006 24007The intrinsic allows the optimizer to assume that the provided condition is 24008always true whenever the control flow reaches the intrinsic call. No code is 24009generated for this intrinsic, and instructions that contribute only to the 24010provided condition are not used for code generation. If the condition is 24011violated during execution, the behavior is undefined. 24012 24013Note that the optimizer might limit the transformations performed on values 24014used by the ``llvm.assume`` intrinsic in order to preserve the instructions 24015only used to form the intrinsic's input argument. This might prove undesirable 24016if the extra information provided by the ``llvm.assume`` intrinsic does not cause 24017sufficient overall improvement in code quality. For this reason, 24018``llvm.assume`` should not be used to document basic mathematical invariants 24019that the optimizer can otherwise deduce or facts that are of little use to the 24020optimizer. 24021 24022.. _int_ssa_copy: 24023 24024'``llvm.ssa.copy``' Intrinsic 24025^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24026 24027Syntax: 24028""""""" 24029 24030:: 24031 24032 declare type @llvm.ssa.copy(type %operand) returned(1) readnone 24033 24034Arguments: 24035"""""""""" 24036 24037The first argument is an operand which is used as the returned value. 24038 24039Overview: 24040"""""""""" 24041 24042The ``llvm.ssa.copy`` intrinsic can be used to attach information to 24043operations by copying them and giving them new names. For example, 24044the PredicateInfo utility uses it to build Extended SSA form, and 24045attach various forms of information to operands that dominate specific 24046uses. It is not meant for general use, only for building temporary 24047renaming forms that require value splits at certain points. 24048 24049.. _type.test: 24050 24051'``llvm.type.test``' Intrinsic 24052^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24053 24054Syntax: 24055""""""" 24056 24057:: 24058 24059 declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone 24060 24061 24062Arguments: 24063"""""""""" 24064 24065The first argument is a pointer to be tested. The second argument is a 24066metadata object representing a :doc:`type identifier <TypeMetadata>`. 24067 24068Overview: 24069""""""""" 24070 24071The ``llvm.type.test`` intrinsic tests whether the given pointer is associated 24072with the given type identifier. 24073 24074.. _type.checked.load: 24075 24076'``llvm.type.checked.load``' Intrinsic 24077^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24078 24079Syntax: 24080""""""" 24081 24082:: 24083 24084 declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly 24085 24086 24087Arguments: 24088"""""""""" 24089 24090The first argument is a pointer from which to load a function pointer. The 24091second argument is the byte offset from which to load the function pointer. The 24092third argument is a metadata object representing a :doc:`type identifier 24093<TypeMetadata>`. 24094 24095Overview: 24096""""""""" 24097 24098The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a 24099virtual table pointer using type metadata. This intrinsic is used to implement 24100control flow integrity in conjunction with virtual call optimization. The 24101virtual call optimization pass will optimize away ``llvm.type.checked.load`` 24102intrinsics associated with devirtualized calls, thereby removing the type 24103check in cases where it is not needed to enforce the control flow integrity 24104constraint. 24105 24106If the given pointer is associated with a type metadata identifier, this 24107function returns true as the second element of its return value. (Note that 24108the function may also return true if the given pointer is not associated 24109with a type metadata identifier.) If the function's return value's second 24110element is true, the following rules apply to the first element: 24111 24112- If the given pointer is associated with the given type metadata identifier, 24113 it is the function pointer loaded from the given byte offset from the given 24114 pointer. 24115 24116- If the given pointer is not associated with the given type metadata 24117 identifier, it is one of the following (the choice of which is unspecified): 24118 24119 1. The function pointer that would have been loaded from an arbitrarily chosen 24120 (through an unspecified mechanism) pointer associated with the type 24121 metadata. 24122 24123 2. If the function has a non-void return type, a pointer to a function that 24124 returns an unspecified value without causing side effects. 24125 24126If the function's return value's second element is false, the value of the 24127first element is undefined. 24128 24129 24130'``llvm.arithmetic.fence``' Intrinsic 24131^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24132 24133Syntax: 24134""""""" 24135 24136:: 24137 24138 declare <type> 24139 @llvm.arithmetic.fence(<type> <op>) 24140 24141Overview: 24142""""""""" 24143 24144The purpose of the ``llvm.arithmetic.fence`` intrinsic 24145is to prevent the optimizer from performing fast-math optimizations, 24146particularly reassociation, 24147between the argument and the expression that contains the argument. 24148It can be used to preserve the parentheses in the source language. 24149 24150Arguments: 24151"""""""""" 24152 24153The ``llvm.arithmetic.fence`` intrinsic takes only one argument. 24154The argument and the return value are floating-point numbers, 24155or vector floating-point numbers, of the same type. 24156 24157Semantics: 24158"""""""""" 24159 24160This intrinsic returns the value of its operand. The optimizer can optimize 24161the argument, but the optimizer cannot hoist any component of the operand 24162to the containing context, and the optimizer cannot move the calculation of 24163any expression in the containing context into the operand. 24164 24165 24166'``llvm.donothing``' Intrinsic 24167^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24168 24169Syntax: 24170""""""" 24171 24172:: 24173 24174 declare void @llvm.donothing() nounwind readnone 24175 24176Overview: 24177""""""""" 24178 24179The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only 24180three intrinsics (besides ``llvm.experimental.patchpoint`` and 24181``llvm.experimental.gc.statepoint``) that can be called with an invoke 24182instruction. 24183 24184Arguments: 24185"""""""""" 24186 24187None. 24188 24189Semantics: 24190"""""""""" 24191 24192This intrinsic does nothing, and it's removed by optimizers and ignored 24193by codegen. 24194 24195'``llvm.experimental.deoptimize``' Intrinsic 24196^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24197 24198Syntax: 24199""""""" 24200 24201:: 24202 24203 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ] 24204 24205Overview: 24206""""""""" 24207 24208This intrinsic, together with :ref:`deoptimization operand bundles 24209<deopt_opbundles>`, allow frontends to express transfer of control and 24210frame-local state from the currently executing (typically more specialized, 24211hence faster) version of a function into another (typically more generic, hence 24212slower) version. 24213 24214In languages with a fully integrated managed runtime like Java and JavaScript 24215this intrinsic can be used to implement "uncommon trap" or "side exit" like 24216functionality. In unmanaged languages like C and C++, this intrinsic can be 24217used to represent the slow paths of specialized functions. 24218 24219 24220Arguments: 24221"""""""""" 24222 24223The intrinsic takes an arbitrary number of arguments, whose meaning is 24224decided by the :ref:`lowering strategy<deoptimize_lowering>`. 24225 24226Semantics: 24227"""""""""" 24228 24229The ``@llvm.experimental.deoptimize`` intrinsic executes an attached 24230deoptimization continuation (denoted using a :ref:`deoptimization 24231operand bundle <deopt_opbundles>`) and returns the value returned by 24232the deoptimization continuation. Defining the semantic properties of 24233the continuation itself is out of scope of the language reference -- 24234as far as LLVM is concerned, the deoptimization continuation can 24235invoke arbitrary side effects, including reading from and writing to 24236the entire heap. 24237 24238Deoptimization continuations expressed using ``"deopt"`` operand bundles always 24239continue execution to the end of the physical frame containing them, so all 24240calls to ``@llvm.experimental.deoptimize`` must be in "tail position": 24241 24242 - ``@llvm.experimental.deoptimize`` cannot be invoked. 24243 - The call must immediately precede a :ref:`ret <i_ret>` instruction. 24244 - The ``ret`` instruction must return the value produced by the 24245 ``@llvm.experimental.deoptimize`` call if there is one, or void. 24246 24247Note that the above restrictions imply that the return type for a call to 24248``@llvm.experimental.deoptimize`` will match the return type of its immediate 24249caller. 24250 24251The inliner composes the ``"deopt"`` continuations of the caller into the 24252``"deopt"`` continuations present in the inlinee, and also updates calls to this 24253intrinsic to return directly from the frame of the function it inlined into. 24254 24255All declarations of ``@llvm.experimental.deoptimize`` must share the 24256same calling convention. 24257 24258.. _deoptimize_lowering: 24259 24260Lowering: 24261""""""""" 24262 24263Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the 24264symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to 24265ensure that this symbol is defined). The call arguments to 24266``@llvm.experimental.deoptimize`` are lowered as if they were formal 24267arguments of the specified types, and not as varargs. 24268 24269 24270'``llvm.experimental.guard``' Intrinsic 24271^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24272 24273Syntax: 24274""""""" 24275 24276:: 24277 24278 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ] 24279 24280Overview: 24281""""""""" 24282 24283This intrinsic, together with :ref:`deoptimization operand bundles 24284<deopt_opbundles>`, allows frontends to express guards or checks on 24285optimistic assumptions made during compilation. The semantics of 24286``@llvm.experimental.guard`` is defined in terms of 24287``@llvm.experimental.deoptimize`` -- its body is defined to be 24288equivalent to: 24289 24290.. code-block:: text 24291 24292 define void @llvm.experimental.guard(i1 %pred, <args...>) { 24293 %realPred = and i1 %pred, undef 24294 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}] 24295 24296 leave: 24297 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ] 24298 ret void 24299 24300 continue: 24301 ret void 24302 } 24303 24304 24305with the optional ``[, !make.implicit !{}]`` present if and only if it 24306is present on the call site. For more details on ``!make.implicit``, 24307see :doc:`FaultMaps`. 24308 24309In words, ``@llvm.experimental.guard`` executes the attached 24310``"deopt"`` continuation if (but **not** only if) its first argument 24311is ``false``. Since the optimizer is allowed to replace the ``undef`` 24312with an arbitrary value, it can optimize guard to fail "spuriously", 24313i.e. without the original condition being false (hence the "not only 24314if"); and this allows for "check widening" type optimizations. 24315 24316``@llvm.experimental.guard`` cannot be invoked. 24317 24318After ``@llvm.experimental.guard`` was first added, a more general 24319formulation was found in ``@llvm.experimental.widenable.condition``. 24320Support for ``@llvm.experimental.guard`` is slowly being rephrased in 24321terms of this alternate. 24322 24323'``llvm.experimental.widenable.condition``' Intrinsic 24324^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24325 24326Syntax: 24327""""""" 24328 24329:: 24330 24331 declare i1 @llvm.experimental.widenable.condition() 24332 24333Overview: 24334""""""""" 24335 24336This intrinsic represents a "widenable condition" which is 24337boolean expressions with the following property: whether this 24338expression is `true` or `false`, the program is correct and 24339well-defined. 24340 24341Together with :ref:`deoptimization operand bundles <deopt_opbundles>`, 24342``@llvm.experimental.widenable.condition`` allows frontends to 24343express guards or checks on optimistic assumptions made during 24344compilation and represent them as branch instructions on special 24345conditions. 24346 24347While this may appear similar in semantics to `undef`, it is very 24348different in that an invocation produces a particular, singular 24349value. It is also intended to be lowered late, and remain available 24350for specific optimizations and transforms that can benefit from its 24351special properties. 24352 24353Arguments: 24354"""""""""" 24355 24356None. 24357 24358Semantics: 24359"""""""""" 24360 24361The intrinsic ``@llvm.experimental.widenable.condition()`` 24362returns either `true` or `false`. For each evaluation of a call 24363to this intrinsic, the program must be valid and correct both if 24364it returns `true` and if it returns `false`. This allows 24365transformation passes to replace evaluations of this intrinsic 24366with either value whenever one is beneficial. 24367 24368When used in a branch condition, it allows us to choose between 24369two alternative correct solutions for the same problem, like 24370in example below: 24371 24372.. code-block:: text 24373 24374 %cond = call i1 @llvm.experimental.widenable.condition() 24375 br i1 %cond, label %solution_1, label %solution_2 24376 24377 label %fast_path: 24378 ; Apply memory-consuming but fast solution for a task. 24379 24380 label %slow_path: 24381 ; Cheap in memory but slow solution. 24382 24383Whether the result of intrinsic's call is `true` or `false`, 24384it should be correct to pick either solution. We can switch 24385between them by replacing the result of 24386``@llvm.experimental.widenable.condition`` with different 24387`i1` expressions. 24388 24389This is how it can be used to represent guards as widenable branches: 24390 24391.. code-block:: text 24392 24393 block: 24394 ; Unguarded instructions 24395 call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)] 24396 ; Guarded instructions 24397 24398Can be expressed in an alternative equivalent form of explicit branch using 24399``@llvm.experimental.widenable.condition``: 24400 24401.. code-block:: text 24402 24403 block: 24404 ; Unguarded instructions 24405 %widenable_condition = call i1 @llvm.experimental.widenable.condition() 24406 %guard_condition = and i1 %cond, %widenable_condition 24407 br i1 %guard_condition, label %guarded, label %deopt 24408 24409 guarded: 24410 ; Guarded instructions 24411 24412 deopt: 24413 call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ] 24414 24415So the block `guarded` is only reachable when `%cond` is `true`, 24416and it should be valid to go to the block `deopt` whenever `%cond` 24417is `true` or `false`. 24418 24419``@llvm.experimental.widenable.condition`` will never throw, thus 24420it cannot be invoked. 24421 24422Guard widening: 24423""""""""""""""" 24424 24425When ``@llvm.experimental.widenable.condition()`` is used in 24426condition of a guard represented as explicit branch, it is 24427legal to widen the guard's condition with any additional 24428conditions. 24429 24430Guard widening looks like replacement of 24431 24432.. code-block:: text 24433 24434 %widenable_cond = call i1 @llvm.experimental.widenable.condition() 24435 %guard_cond = and i1 %cond, %widenable_cond 24436 br i1 %guard_cond, label %guarded, label %deopt 24437 24438with 24439 24440.. code-block:: text 24441 24442 %widenable_cond = call i1 @llvm.experimental.widenable.condition() 24443 %new_cond = and i1 %any_other_cond, %widenable_cond 24444 %new_guard_cond = and i1 %cond, %new_cond 24445 br i1 %new_guard_cond, label %guarded, label %deopt 24446 24447for this branch. Here `%any_other_cond` is an arbitrarily chosen 24448well-defined `i1` value. By making guard widening, we may 24449impose stricter conditions on `guarded` block and bail to the 24450deopt when the new condition is not met. 24451 24452Lowering: 24453""""""""" 24454 24455Default lowering strategy is replacing the result of 24456call of ``@llvm.experimental.widenable.condition`` with 24457constant `true`. However it is always correct to replace 24458it with any other `i1` value. Any pass can 24459freely do it if it can benefit from non-default lowering. 24460 24461 24462'``llvm.load.relative``' Intrinsic 24463^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24464 24465Syntax: 24466""""""" 24467 24468:: 24469 24470 declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly 24471 24472Overview: 24473""""""""" 24474 24475This intrinsic loads a 32-bit value from the address ``%ptr + %offset``, 24476adds ``%ptr`` to that value and returns it. The constant folder specifically 24477recognizes the form of this intrinsic and the constant initializers it may 24478load from; if a loaded constant initializer is known to have the form 24479``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``. 24480 24481LLVM provides that the calculation of such a constant initializer will 24482not overflow at link time under the medium code model if ``x`` is an 24483``unnamed_addr`` function. However, it does not provide this guarantee for 24484a constant initializer folded into a function body. This intrinsic can be 24485used to avoid the possibility of overflows when loading from such a constant. 24486 24487.. _llvm_sideeffect: 24488 24489'``llvm.sideeffect``' Intrinsic 24490^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24491 24492Syntax: 24493""""""" 24494 24495:: 24496 24497 declare void @llvm.sideeffect() inaccessiblememonly nounwind willreturn 24498 24499Overview: 24500""""""""" 24501 24502The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers 24503treat it as having side effects, so it can be inserted into a loop to 24504indicate that the loop shouldn't be assumed to terminate (which could 24505potentially lead to the loop being optimized away entirely), even if it's 24506an infinite loop with no other side effects. 24507 24508Arguments: 24509"""""""""" 24510 24511None. 24512 24513Semantics: 24514"""""""""" 24515 24516This intrinsic actually does nothing, but optimizers must assume that it 24517has externally observable side effects. 24518 24519'``llvm.is.constant.*``' Intrinsic 24520^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24521 24522Syntax: 24523""""""" 24524 24525This is an overloaded intrinsic. You can use llvm.is.constant with any argument type. 24526 24527:: 24528 24529 declare i1 @llvm.is.constant.i32(i32 %operand) nounwind readnone 24530 declare i1 @llvm.is.constant.f32(float %operand) nounwind readnone 24531 declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind readnone 24532 24533Overview: 24534""""""""" 24535 24536The '``llvm.is.constant``' intrinsic will return true if the argument 24537is known to be a manifest compile-time constant. It is guaranteed to 24538fold to either true or false before generating machine code. 24539 24540Semantics: 24541"""""""""" 24542 24543This intrinsic generates no code. If its argument is known to be a 24544manifest compile-time constant value, then the intrinsic will be 24545converted to a constant true value. Otherwise, it will be converted to 24546a constant false value. 24547 24548In particular, note that if the argument is a constant expression 24549which refers to a global (the address of which _is_ a constant, but 24550not manifest during the compile), then the intrinsic evaluates to 24551false. 24552 24553The result also intentionally depends on the result of optimization 24554passes -- e.g., the result can change depending on whether a 24555function gets inlined or not. A function's parameters are 24556obviously not constant. However, a call like 24557``llvm.is.constant.i32(i32 %param)`` *can* return true after the 24558function is inlined, if the value passed to the function parameter was 24559a constant. 24560 24561On the other hand, if constant folding is not run, it will never 24562evaluate to true, even in simple cases. 24563 24564.. _int_ptrmask: 24565 24566'``llvm.ptrmask``' Intrinsic 24567^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24568 24569Syntax: 24570""""""" 24571 24572:: 24573 24574 declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) readnone speculatable 24575 24576Arguments: 24577"""""""""" 24578 24579The first argument is a pointer. The second argument is an integer. 24580 24581Overview: 24582"""""""""" 24583 24584The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask. 24585This allows stripping data from tagged pointers without converting them to an 24586integer (ptrtoint/inttoptr). As a consequence, we can preserve more information 24587to facilitate alias analysis and underlying-object detection. 24588 24589Semantics: 24590"""""""""" 24591 24592The result of ``ptrmask(ptr, mask)`` is equivalent to 24593``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned 24594pointer and the first argument are based on the same underlying object (for more 24595information on the *based on* terminology see 24596:ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the 24597mask argument does not match the pointer size of the target, the mask is 24598zero-extended or truncated accordingly. 24599 24600.. _int_vscale: 24601 24602'``llvm.vscale``' Intrinsic 24603^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24604 24605Syntax: 24606""""""" 24607 24608:: 24609 24610 declare i32 llvm.vscale.i32() 24611 declare i64 llvm.vscale.i64() 24612 24613Overview: 24614""""""""" 24615 24616The ``llvm.vscale`` intrinsic returns the value for ``vscale`` in scalable 24617vectors such as ``<vscale x 16 x i8>``. 24618 24619Semantics: 24620"""""""""" 24621 24622``vscale`` is a positive value that is constant throughout program 24623execution, but is unknown at compile time. 24624If the result value does not fit in the result type, then the result is 24625a :ref:`poison value <poisonvalues>`. 24626 24627 24628Stack Map Intrinsics 24629-------------------- 24630 24631LLVM provides experimental intrinsics to support runtime patching 24632mechanisms commonly desired in dynamic language JITs. These intrinsics 24633are described in :doc:`StackMaps`. 24634 24635Element Wise Atomic Memory Intrinsics 24636------------------------------------- 24637 24638These intrinsics are similar to the standard library memory intrinsics except 24639that they perform memory transfer as a sequence of atomic memory accesses. 24640 24641.. _int_memcpy_element_unordered_atomic: 24642 24643'``llvm.memcpy.element.unordered.atomic``' Intrinsic 24644^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24645 24646Syntax: 24647""""""" 24648 24649This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on 24650any integer bit width and for different address spaces. Not all targets 24651support all bit widths however. 24652 24653:: 24654 24655 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>, 24656 i8* <src>, 24657 i32 <len>, 24658 i32 <element_size>) 24659 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>, 24660 i8* <src>, 24661 i64 <len>, 24662 i32 <element_size>) 24663 24664Overview: 24665""""""""" 24666 24667The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the 24668'``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated 24669as arrays with elements that are exactly ``element_size`` bytes, and the copy between 24670buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations 24671that are a positive integer multiple of the ``element_size`` in size. 24672 24673Arguments: 24674"""""""""" 24675 24676The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>` 24677intrinsic, with the added constraint that ``len`` is required to be a positive integer 24678multiple of the ``element_size``. If ``len`` is not a positive integer multiple of 24679``element_size``, then the behaviour of the intrinsic is undefined. 24680 24681``element_size`` must be a compile-time constant positive power of two no greater than 24682target-specific atomic access size limit. 24683 24684For each of the input pointers ``align`` parameter attribute must be specified. It 24685must be a power of two no less than the ``element_size``. Caller guarantees that 24686both the source and destination pointers are aligned to that boundary. 24687 24688Semantics: 24689"""""""""" 24690 24691The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of 24692memory from the source location to the destination location. These locations are not 24693allowed to overlap. The memory copy is performed as a sequence of load/store operations 24694where each access is guaranteed to be a multiple of ``element_size`` bytes wide and 24695aligned at an ``element_size`` boundary. 24696 24697The order of the copy is unspecified. The same value may be read from the source 24698buffer many times, but only one write is issued to the destination buffer per 24699element. It is well defined to have concurrent reads and writes to both source and 24700destination provided those reads and writes are unordered atomic when specified. 24701 24702This intrinsic does not provide any additional ordering guarantees over those 24703provided by a set of unordered loads from the source location and stores to the 24704destination. 24705 24706Lowering: 24707""""""""" 24708 24709In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is 24710lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*' 24711is replaced with an actual element size. See :ref:`RewriteStatepointsForGC intrinsic 24712lowering <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific 24713lowering. 24714 24715Optimizer is allowed to inline memory copy when it's profitable to do so. 24716 24717'``llvm.memmove.element.unordered.atomic``' Intrinsic 24718^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24719 24720Syntax: 24721""""""" 24722 24723This is an overloaded intrinsic. You can use 24724``llvm.memmove.element.unordered.atomic`` on any integer bit width and for 24725different address spaces. Not all targets support all bit widths however. 24726 24727:: 24728 24729 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>, 24730 i8* <src>, 24731 i32 <len>, 24732 i32 <element_size>) 24733 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>, 24734 i8* <src>, 24735 i64 <len>, 24736 i32 <element_size>) 24737 24738Overview: 24739""""""""" 24740 24741The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization 24742of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and 24743``src`` are treated as arrays with elements that are exactly ``element_size`` 24744bytes, and the copy between buffers uses a sequence of 24745:ref:`unordered atomic <ordering>` load/store operations that are a positive 24746integer multiple of the ``element_size`` in size. 24747 24748Arguments: 24749"""""""""" 24750 24751The first three arguments are the same as they are in the 24752:ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that 24753``len`` is required to be a positive integer multiple of the ``element_size``. 24754If ``len`` is not a positive integer multiple of ``element_size``, then the 24755behaviour of the intrinsic is undefined. 24756 24757``element_size`` must be a compile-time constant positive power of two no 24758greater than a target-specific atomic access size limit. 24759 24760For each of the input pointers the ``align`` parameter attribute must be 24761specified. It must be a power of two no less than the ``element_size``. Caller 24762guarantees that both the source and destination pointers are aligned to that 24763boundary. 24764 24765Semantics: 24766"""""""""" 24767 24768The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes 24769of memory from the source location to the destination location. These locations 24770are allowed to overlap. The memory copy is performed as a sequence of load/store 24771operations where each access is guaranteed to be a multiple of ``element_size`` 24772bytes wide and aligned at an ``element_size`` boundary. 24773 24774The order of the copy is unspecified. The same value may be read from the source 24775buffer many times, but only one write is issued to the destination buffer per 24776element. It is well defined to have concurrent reads and writes to both source 24777and destination provided those reads and writes are unordered atomic when 24778specified. 24779 24780This intrinsic does not provide any additional ordering guarantees over those 24781provided by a set of unordered loads from the source location and stores to the 24782destination. 24783 24784Lowering: 24785""""""""" 24786 24787In the most general case call to the 24788'``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol 24789``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an 24790actual element size. See :ref:`RewriteStatepointsForGC intrinsic lowering 24791<RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific 24792lowering. 24793 24794The optimizer is allowed to inline the memory copy when it's profitable to do so. 24795 24796.. _int_memset_element_unordered_atomic: 24797 24798'``llvm.memset.element.unordered.atomic``' Intrinsic 24799^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24800 24801Syntax: 24802""""""" 24803 24804This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on 24805any integer bit width and for different address spaces. Not all targets 24806support all bit widths however. 24807 24808:: 24809 24810 declare void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* <dest>, 24811 i8 <value>, 24812 i32 <len>, 24813 i32 <element_size>) 24814 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* <dest>, 24815 i8 <value>, 24816 i64 <len>, 24817 i32 <element_size>) 24818 24819Overview: 24820""""""""" 24821 24822The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the 24823'``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array 24824with elements that are exactly ``element_size`` bytes, and the assignment to that array 24825uses uses a sequence of :ref:`unordered atomic <ordering>` store operations 24826that are a positive integer multiple of the ``element_size`` in size. 24827 24828Arguments: 24829"""""""""" 24830 24831The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>` 24832intrinsic, with the added constraint that ``len`` is required to be a positive integer 24833multiple of the ``element_size``. If ``len`` is not a positive integer multiple of 24834``element_size``, then the behaviour of the intrinsic is undefined. 24835 24836``element_size`` must be a compile-time constant positive power of two no greater than 24837target-specific atomic access size limit. 24838 24839The ``dest`` input pointer must have the ``align`` parameter attribute specified. It 24840must be a power of two no less than the ``element_size``. Caller guarantees that 24841the destination pointer is aligned to that boundary. 24842 24843Semantics: 24844"""""""""" 24845 24846The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of 24847memory starting at the destination location to the given ``value``. The memory is 24848set with a sequence of store operations where each access is guaranteed to be a 24849multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary. 24850 24851The order of the assignment is unspecified. Only one write is issued to the 24852destination buffer per element. It is well defined to have concurrent reads and 24853writes to the destination provided those reads and writes are unordered atomic 24854when specified. 24855 24856This intrinsic does not provide any additional ordering guarantees over those 24857provided by a set of unordered stores to the destination. 24858 24859Lowering: 24860""""""""" 24861 24862In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is 24863lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*' 24864is replaced with an actual element size. 24865 24866The optimizer is allowed to inline the memory assignment when it's profitable to do so. 24867 24868Objective-C ARC Runtime Intrinsics 24869---------------------------------- 24870 24871LLVM provides intrinsics that lower to Objective-C ARC runtime entry points. 24872LLVM is aware of the semantics of these functions, and optimizes based on that 24873knowledge. You can read more about the details of Objective-C ARC `here 24874<https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_. 24875 24876'``llvm.objc.autorelease``' Intrinsic 24877^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24878 24879Syntax: 24880""""""" 24881:: 24882 24883 declare i8* @llvm.objc.autorelease(i8*) 24884 24885Lowering: 24886""""""""" 24887 24888Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_. 24889 24890'``llvm.objc.autoreleasePoolPop``' Intrinsic 24891^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24892 24893Syntax: 24894""""""" 24895:: 24896 24897 declare void @llvm.objc.autoreleasePoolPop(i8*) 24898 24899Lowering: 24900""""""""" 24901 24902Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_. 24903 24904'``llvm.objc.autoreleasePoolPush``' Intrinsic 24905^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24906 24907Syntax: 24908""""""" 24909:: 24910 24911 declare i8* @llvm.objc.autoreleasePoolPush() 24912 24913Lowering: 24914""""""""" 24915 24916Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_. 24917 24918'``llvm.objc.autoreleaseReturnValue``' Intrinsic 24919^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24920 24921Syntax: 24922""""""" 24923:: 24924 24925 declare i8* @llvm.objc.autoreleaseReturnValue(i8*) 24926 24927Lowering: 24928""""""""" 24929 24930Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_. 24931 24932'``llvm.objc.copyWeak``' Intrinsic 24933^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24934 24935Syntax: 24936""""""" 24937:: 24938 24939 declare void @llvm.objc.copyWeak(i8**, i8**) 24940 24941Lowering: 24942""""""""" 24943 24944Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_. 24945 24946'``llvm.objc.destroyWeak``' Intrinsic 24947^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24948 24949Syntax: 24950""""""" 24951:: 24952 24953 declare void @llvm.objc.destroyWeak(i8**) 24954 24955Lowering: 24956""""""""" 24957 24958Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_. 24959 24960'``llvm.objc.initWeak``' Intrinsic 24961^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24962 24963Syntax: 24964""""""" 24965:: 24966 24967 declare i8* @llvm.objc.initWeak(i8**, i8*) 24968 24969Lowering: 24970""""""""" 24971 24972Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_. 24973 24974'``llvm.objc.loadWeak``' Intrinsic 24975^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24976 24977Syntax: 24978""""""" 24979:: 24980 24981 declare i8* @llvm.objc.loadWeak(i8**) 24982 24983Lowering: 24984""""""""" 24985 24986Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_. 24987 24988'``llvm.objc.loadWeakRetained``' Intrinsic 24989^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24990 24991Syntax: 24992""""""" 24993:: 24994 24995 declare i8* @llvm.objc.loadWeakRetained(i8**) 24996 24997Lowering: 24998""""""""" 24999 25000Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_. 25001 25002'``llvm.objc.moveWeak``' Intrinsic 25003^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25004 25005Syntax: 25006""""""" 25007:: 25008 25009 declare void @llvm.objc.moveWeak(i8**, i8**) 25010 25011Lowering: 25012""""""""" 25013 25014Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_. 25015 25016'``llvm.objc.release``' Intrinsic 25017^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25018 25019Syntax: 25020""""""" 25021:: 25022 25023 declare void @llvm.objc.release(i8*) 25024 25025Lowering: 25026""""""""" 25027 25028Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_. 25029 25030'``llvm.objc.retain``' Intrinsic 25031^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25032 25033Syntax: 25034""""""" 25035:: 25036 25037 declare i8* @llvm.objc.retain(i8*) 25038 25039Lowering: 25040""""""""" 25041 25042Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_. 25043 25044'``llvm.objc.retainAutorelease``' Intrinsic 25045^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25046 25047Syntax: 25048""""""" 25049:: 25050 25051 declare i8* @llvm.objc.retainAutorelease(i8*) 25052 25053Lowering: 25054""""""""" 25055 25056Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_. 25057 25058'``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic 25059^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25060 25061Syntax: 25062""""""" 25063:: 25064 25065 declare i8* @llvm.objc.retainAutoreleaseReturnValue(i8*) 25066 25067Lowering: 25068""""""""" 25069 25070Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_. 25071 25072'``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic 25073^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25074 25075Syntax: 25076""""""" 25077:: 25078 25079 declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*) 25080 25081Lowering: 25082""""""""" 25083 25084Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_. 25085 25086'``llvm.objc.retainBlock``' Intrinsic 25087^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25088 25089Syntax: 25090""""""" 25091:: 25092 25093 declare i8* @llvm.objc.retainBlock(i8*) 25094 25095Lowering: 25096""""""""" 25097 25098Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_. 25099 25100'``llvm.objc.storeStrong``' Intrinsic 25101^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25102 25103Syntax: 25104""""""" 25105:: 25106 25107 declare void @llvm.objc.storeStrong(i8**, i8*) 25108 25109Lowering: 25110""""""""" 25111 25112Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_. 25113 25114'``llvm.objc.storeWeak``' Intrinsic 25115^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25116 25117Syntax: 25118""""""" 25119:: 25120 25121 declare i8* @llvm.objc.storeWeak(i8**, i8*) 25122 25123Lowering: 25124""""""""" 25125 25126Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_. 25127 25128Preserving Debug Information Intrinsics 25129^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25130 25131These intrinsics are used to carry certain debuginfo together with 25132IR-level operations. For example, it may be desirable to 25133know the structure/union name and the original user-level field 25134indices. Such information got lost in IR GetElementPtr instruction 25135since the IR types are different from debugInfo types and unions 25136are converted to structs in IR. 25137 25138'``llvm.preserve.array.access.index``' Intrinsic 25139^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25140 25141Syntax: 25142""""""" 25143:: 25144 25145 declare <ret_type> 25146 @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base, 25147 i32 dim, 25148 i32 index) 25149 25150Overview: 25151""""""""" 25152 25153The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address 25154based on array base ``base``, array dimension ``dim`` and the last access index ``index`` 25155into the array. The return type ``ret_type`` is a pointer type to the array element. 25156The array ``dim`` and ``index`` are preserved which is more robust than 25157getelementptr instruction which may be subject to compiler transformation. 25158The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 25159to provide array or pointer debuginfo type. 25160The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the 25161debuginfo version of ``type``. 25162 25163Arguments: 25164"""""""""" 25165 25166The ``base`` is the array base address. The ``dim`` is the array dimension. 25167The ``base`` is a pointer if ``dim`` equals 0. 25168The ``index`` is the last access index into the array or pointer. 25169 25170The ``base`` argument must be annotated with an :ref:`elementtype 25171<attr_elementtype>` attribute at the call-site. This attribute specifies the 25172getelementptr element type. 25173 25174Semantics: 25175"""""""""" 25176 25177The '``llvm.preserve.array.access.index``' intrinsic produces the same result 25178as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``. 25179 25180'``llvm.preserve.union.access.index``' Intrinsic 25181^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25182 25183Syntax: 25184""""""" 25185:: 25186 25187 declare <type> 25188 @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base, 25189 i32 di_index) 25190 25191Overview: 25192""""""""" 25193 25194The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index 25195``di_index`` and returns the ``base`` address. 25196The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 25197to provide union debuginfo type. 25198The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``. 25199The return type ``type`` is the same as the ``base`` type. 25200 25201Arguments: 25202"""""""""" 25203 25204The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo. 25205 25206Semantics: 25207"""""""""" 25208 25209The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address. 25210 25211'``llvm.preserve.struct.access.index``' Intrinsic 25212^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25213 25214Syntax: 25215""""""" 25216:: 25217 25218 declare <ret_type> 25219 @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base, 25220 i32 gep_index, 25221 i32 di_index) 25222 25223Overview: 25224""""""""" 25225 25226The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address 25227based on struct base ``base`` and IR struct member index ``gep_index``. 25228The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 25229to provide struct debuginfo type. 25230The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``. 25231The return type ``ret_type`` is a pointer type to the structure member. 25232 25233Arguments: 25234"""""""""" 25235 25236The ``base`` is the structure base address. The ``gep_index`` is the struct member index 25237based on IR structures. The ``di_index`` is the struct member index based on debuginfo. 25238 25239The ``base`` argument must be annotated with an :ref:`elementtype 25240<attr_elementtype>` attribute at the call-site. This attribute specifies the 25241getelementptr element type. 25242 25243Semantics: 25244"""""""""" 25245 25246The '``llvm.preserve.struct.access.index``' intrinsic produces the same result 25247as a getelementptr with base ``base`` and access operands ``{0, gep_index}``. 25248 25249'``llvm.fptrunc.round``' Intrinsic 25250^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25251 25252Syntax: 25253""""""" 25254 25255:: 25256 25257 declare <ty2> 25258 @llvm.fptrunc.round(<type> <value>, metadata <rounding mode>) 25259 25260Overview: 25261""""""""" 25262 25263The '``llvm.fptrunc.round``' intrinsic truncates 25264:ref:`floating-point <t_floating>` ``value`` to type ``ty2`` 25265with a specified rounding mode. 25266 25267Arguments: 25268"""""""""" 25269 25270The '``llvm.fptrunc.round``' intrinsic takes a :ref:`floating-point 25271<t_floating>` value to cast and a :ref:`floating-point <t_floating>` type 25272to cast it to. This argument must be larger in size than the result. 25273 25274The second argument specifies the rounding mode as described in the constrained 25275intrinsics section. 25276For this intrinsic, the "round.dynamic" mode is not supported. 25277 25278Semantics: 25279"""""""""" 25280 25281The '``llvm.fptrunc.round``' intrinsic casts a ``value`` from a larger 25282:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 25283<t_floating>` type. 25284This intrinsic is assumed to execute in the default :ref:`floating-point 25285environment <floatenv>` *except* for the rounding mode. 25286This intrinsic is not supported on all targets. Some targets may not support 25287all rounding modes. 25288