12 This documentation does not yet fully account for vectors. Many of the
13 scalar/integer/floating-point operations can also take vectors.
25 %0:_(s32) = G_IMPLICIT_DEF
34 %0:_(s32) = G_CONSTANT i32 1
39 A floating point constant.
43 %0:_(s32) = G_FCONSTANT float 1.0
48 The address of an object in the stack frame.
52 %1:_(p0) = G_FRAME_INDEX %stack.0.ptr0
57 The address of a global value.
61 %0(p0) = G_GLOBAL_VALUE @var_local
66 The address of a basic block.
70 %0:_(p0) = G_BLOCK_ADDR blockaddress(@test_blockaddress, %ir-block.block)
75 The address of an object in the constant pool.
79 %0:_(p0) = G_CONSTANT_POOL %const.0
81 Integer Extension and Truncation
82 --------------------------------
87 Extend the underlying scalar type of an operation, leaving the high bits
92 %1:_(s32) = G_ANYEXT %0:_(s16)
97 Sign extend the underlying scalar type of an operation, copying the sign bit
98 into the newly-created space.
102 %1:_(s32) = G_SEXT %0:_(s16)
107 Sign extend the value from an arbitrary bit position, copying the sign bit
108 into all bits above it. This is equivalent to a shl + ashr pair with an
109 appropriate shift amount. $sz is an immediate (MachineOperand::isImm()
110 returns true) to allow targets to have some bitwidths legal and others
111 lowered. This opcode is particularly useful if the target has sign-extension
112 instructions that are cheaper than the constituent shifts as the optimizer is
113 able to make decisions on whether it's better to hang on to the G_SEXT_INREG
114 or to lower it and optimize the individual shifts.
118 %1:_(s32) = G_SEXT_INREG %0:_(s32), 16
123 Zero extend the underlying scalar type of an operation, putting zero bits
124 into the newly-created space.
128 %1:_(s32) = G_ZEXT %0:_(s16)
133 Truncate the underlying scalar type of an operation. This is equivalent to
134 G_EXTRACT for scalar types, but acts elementwise on vectors.
138 %1:_(s16) = G_TRUNC %0:_(s32)
146 Convert an integer to a pointer.
150 %1:_(p0) = G_INTTOPTR %0:_(s32)
155 Convert a pointer to an integer.
159 %1:_(s32) = G_PTRTOINT %0:_(p0)
164 Reinterpret a value as a new type. This is usually done without
165 changing any bits but this is not always the case due a subtlety in the
166 definition of the :ref:`LLVM-IR Bitcast Instruction <i_bitcast>`. It
167 is allowed to bitcast between pointers with the same size, but
168 different address spaces.
172 %1:_(s64) = G_BITCAST %0:_(<2 x s32>)
177 Convert a pointer to an address space to a pointer to another address space.
181 %1:_(p1) = G_ADDRSPACE_CAST %0:_(p0)
185 :ref:`i_addrspacecast` doesn't mention what happens if the cast is simply
186 invalid (i.e. if the address spaces are disjoint).
194 Extract a register of the specified size, starting from the block given by
195 index. This will almost certainly be mapped to sub-register COPYs after
196 register banks have been selected.
200 %3:_(s32) = G_EXTRACT %2:_(s64), 32
205 Insert a smaller register into a larger one at the specified bit-index.
209 %2:_(s64) = G_INSERT %0:(_s64), %1:_(s32), 0
214 Concatenate multiple registers of the same size into a wider register.
215 The input operands are always ordered from lowest bits to highest:
219 %0:(s32) = G_MERGE_VALUES %bits_0_7:(s8), %bits_8_15:(s8),
220 %bits_16_23:(s8), %bits_24_31:(s8)
225 Extract multiple registers of the specified size, starting from blocks given by
226 indexes. This will almost certainly be mapped to sub-register COPYs after
227 register banks have been selected.
228 The output operands are always ordered from lowest bits to highest:
232 %bits_0_7:(s8), %bits_8_15:(s8),
233 %bits_16_23:(s8), %bits_24_31:(s8) = G_UNMERGE_VALUES %0:(s32)
238 Reverse the order of the bytes in a scalar.
242 %1:_(s32) = G_BSWAP %0:_(s32)
247 Reverse the order of the bits in a scalar.
251 %1:_(s32) = G_BITREVERSE %0:_(s32)
256 Extract a range of bits from a register.
258 The source operands are registers as follows:
261 - The least-significant bit for the extraction
262 - The width of the extraction
264 The least-significant bit (lsb) and width operands are in the range:
268 0 <= lsb < lsb + width <= source bitwidth, where all values are unsigned
270 G_SBFX sign-extends the result, while G_UBFX zero-extends the result.
274 ; Extract 5 bits starting at bit 1 from %x and store them in %a.
275 ; Sign-extend the result.
278 ; %x = 0...0000[10110]1 ---> %a = 1...111111[10110]
279 %lsb_one = G_CONSTANT i32 1
280 %width_five = G_CONSTANT i32 5
281 %a:_(s32) = G_SBFX %x, %lsb_one, %width_five
283 ; Extract 3 bits starting at bit 2 from %x and store them in %b. Zero-extend
287 ; %x = 1...11111[100]11 ---> %b = 0...00000[100]
288 %lsb_two = G_CONSTANT i32 2
289 %width_three = G_CONSTANT i32 3
290 %b:_(s32) = G_UBFX %x, %lsb_two, %width_three
295 G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR, G_SDIV, G_UDIV, G_SREM, G_UREM
296 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
298 These each perform their respective integer arithmetic on a scalar.
302 %dst:_(s32) = G_ADD %src0:_(s32), %src1:_(s32)
304 The above example adds %src1 to %src0 and stores the result in %dst.
309 Perform integer division and remainder thereby producing two results.
313 %div:_(s32), %rem:_(s32) = G_SDIVREM %0:_(s32), %1:_(s32)
315 G_SADDSAT, G_UADDSAT, G_SSUBSAT, G_USUBSAT, G_SSHLSAT, G_USHLSAT
316 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
318 Signed and unsigned addition, subtraction and left shift with saturation.
322 %2:_(s32) = G_SADDSAT %0:_(s32), %1:_(s32)
324 G_SHL, G_LSHR, G_ASHR
325 ^^^^^^^^^^^^^^^^^^^^^
327 Shift the bits of a scalar left or right inserting zeros (sign-bit for G_ASHR).
332 Rotate the bits right (G_ROTR) or left (G_ROTL).
337 Perform integer comparison producing non-zero (true) or zero (false). It's
338 target specific whether a true value is 1, ~0U, or some other non-zero value.
343 Select between two values depending on a zero/non-zero value.
347 %5:_(s32) = G_SELECT %4(s1), %6, %2
352 Add a scalar offset in addressible units to a pointer. Addressible units are
353 typically bytes but this may vary between targets.
357 %1:_(p0) = G_PTR_ADD %0:_(p0), %1:_(s32)
361 There are currently no in-tree targets that use this with addressable units
367 Zero out an arbitrary mask of bits of a pointer. The mask type must be
368 an integer, and the number of vector elements must match for all
369 operands. This corresponds to `i_intr_llvm_ptrmask`.
373 %2:_(p0) = G_PTRMASK %0, %1
375 G_SMIN, G_SMAX, G_UMIN, G_UMAX
376 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
378 Take the minimum/maximum of two values.
382 %5:_(s32) = G_SMIN %6, %2
385 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
387 Take the absolute value of a signed integer. The absolute value of the minimum
388 negative value (e.g. the 8-bit value `0x80`) is defined to be itself.
394 G_UADDO, G_SADDO, G_USUBO, G_SSUBO, G_SMULO, G_UMULO
395 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
397 Perform the requested arithmetic and produce a carry output in addition to the
402 %3:_(s32), %4:_(s1) = G_UADDO %0, %1
404 G_UADDE, G_SADDE, G_USUBE, G_SSUBE
405 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
407 Perform the requested arithmetic and consume a carry input in addition to the
408 normal input. Also produce a carry output in addition to the normal result.
412 %4:_(s32), %5:_(s1) = G_UADDE %0, %1, %3:_(s1)
417 Multiply two numbers at twice the incoming bit width (unsigned or signed) and
418 return the high half of the result.
422 %3:_(s32) = G_UMULH %0, %1
424 G_CTLZ, G_CTTZ, G_CTPOP
425 ^^^^^^^^^^^^^^^^^^^^^^^
427 Count leading zeros, trailing zeros, or number of set bits.
431 %2:_(s33) = G_CTLZ_ZERO_UNDEF %1
432 %2:_(s33) = G_CTTZ_ZERO_UNDEF %1
433 %2:_(s33) = G_CTPOP %1
435 G_CTLZ_ZERO_UNDEF, G_CTTZ_ZERO_UNDEF
436 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
438 Count leading zeros or trailing zeros. If the value is zero then the result is
443 %2:_(s33) = G_CTLZ_ZERO_UNDEF %1
444 %2:_(s33) = G_CTTZ_ZERO_UNDEF %1
446 Floating Point Operations
447 -------------------------
452 Perform floating point comparison producing non-zero (true) or zero
453 (false). It's target specific whether a true value is 1, ~0U, or some other
459 Floating point negation.
464 Convert a floating point value to a larger type.
469 Convert a floating point value to a narrower type.
471 G_FPTOSI, G_FPTOUI, G_SITOFP, G_UITOFP
472 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
474 Convert between integer and floating point.
479 Take the absolute value of a floating point value.
484 Copy the value of the first operand, replacing the sign bit with that of the
490 See :ref:`i_intr_llvm_canonicalize`.
495 Tests if the first operand, which must be floating-point scalar or vector, has
496 floating-point class specified by the second operand. Returns non-zero (true)
497 or zero (false). It's target specific whether a true value is 1, ~0U, or some
498 other non-zero value. If the first operand is a vector, the returned value is a
499 vector of the same length.
504 Perform floating-point minimum on two values.
506 In the case where a single input is a NaN (either signaling or quiet),
507 the non-NaN input is returned.
509 The return value of (FMINNUM 0.0, -0.0) could be either 0.0 or -0.0.
514 Perform floating-point maximum on two values.
516 In the case where a single input is a NaN (either signaling or quiet),
517 the non-NaN input is returned.
519 The return value of (FMAXNUM 0.0, -0.0) could be either 0.0 or -0.0.
524 Perform floating-point minimum on two values, following the IEEE-754 2008
525 definition. This differs from FMINNUM in the handling of signaling NaNs. If one
526 input is a signaling NaN, returns a quiet NaN.
531 Perform floating-point maximum on two values, following the IEEE-754 2008
532 definition. This differs from FMAXNUM in the handling of signaling NaNs. If one
533 input is a signaling NaN, returns a quiet NaN.
538 NaN-propagating minimum that also treat -0.0 as less than 0.0. While
539 FMINNUM_IEEE follow IEEE 754-2008 semantics, FMINIMUM follows IEEE 754-2018
545 NaN-propagating maximum that also treat -0.0 as less than 0.0. While
546 FMAXNUM_IEEE follow IEEE 754-2008 semantics, FMAXIMUM follows IEEE 754-2018
549 G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FREM
550 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
552 Perform the specified floating point arithmetic.
557 Perform a fused multiply add (i.e. without the intermediate rounding step).
562 Perform a non-fused multiply add (i.e. with the intermediate rounding step).
567 Raise the first operand to the power of the second.
572 Calculate the base-e or base-2 exponential of a value
574 G_FLOG, G_FLOG2, G_FLOG10
575 ^^^^^^^^^^^^^^^^^^^^^^^^^
577 Calculate the base-e, base-2, or base-10 respectively.
579 G_FCEIL, G_FCOS, G_FSIN, G_FSQRT, G_FFLOOR, G_FRINT, G_FNEARBYINT
580 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
582 These correspond to the standard C functions of the same name.
587 Returns the operand rounded to the nearest integer not larger in magnitude than the operand.
592 Returns the operand rounded to the nearest integer.
597 Returns the source operand rounded to the nearest integer with ties away from
600 See the LLVM LangRef entry on '``llvm.lround.*'`` for details on behaviour.
604 %rounded_32:_(s32) = G_LROUND %round_me:_(s64)
605 %rounded_64:_(s64) = G_LLROUND %round_me:_(s64)
607 Vector Specific Operations
608 --------------------------
613 Concatenate two vectors to form a longer vector.
615 G_BUILD_VECTOR, G_BUILD_VECTOR_TRUNC
616 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
618 Create a vector from multiple scalar registers. No implicit
619 conversion is performed (i.e. the result element type must be the
620 same as all source operands)
622 The _TRUNC version truncates the larger operand types to fit the
623 destination vector elt type.
628 Insert an element into a vector
633 Extract an element from a vector
638 Concatenate two vectors and shuffle the elements according to the mask operand.
639 The mask operand should be an IR Constant which exactly matches the
640 corresponding mask for the IR shufflevector instruction.
642 Vector Reduction Operations
643 ---------------------------
645 These operations represent horizontal vector reduction, producing a scalar result.
647 G_VECREDUCE_SEQ_FADD, G_VECREDUCE_SEQ_FMUL
648 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
650 The SEQ variants perform reductions in sequential order. The first operand is
651 an initial scalar accumulator value, and the second operand is the vector to reduce.
653 G_VECREDUCE_FADD, G_VECREDUCE_FMUL
654 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
656 These reductions are relaxed variants which may reduce the elements in any order.
658 G_VECREDUCE_FMAX, G_VECREDUCE_FMIN, G_VECREDUCE_FMAXIMUM, G_VECREDUCE_FMINIMUM
659 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
661 FMIN/FMAX/FMINIMUM/FMAXIMUM nodes can have flags, for NaN/NoNaN variants.
664 Integer/bitwise reductions
665 ^^^^^^^^^^^^^^^^^^^^^^^^^^
677 Integer reductions may have a result type larger than the vector element type.
678 However, the reduction is performed using the vector element type and the value
679 in the top bits is unspecified.
684 G_LOAD, G_SEXTLOAD, G_ZEXTLOAD
685 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
687 Generic load. Expects a MachineMemOperand in addition to explicit
688 operands. If the result size is larger than the memory size, the
689 high bits are undefined, sign-extended, or zero-extended respectively.
691 Only G_LOAD is valid if the result is a vector type. If the result is larger
692 than the memory size, the high elements are undefined (i.e. this is not a
693 per-element, vector anyextload)
695 Unlike in SelectionDAG, atomic loads are expressed with the same
696 opcodes as regular loads. G_LOAD, G_SEXTLOAD and G_ZEXTLOAD may all
697 have atomic memory operands.
702 Generic indexed load. Combines a GEP with a load. $newaddr is set to $base + $offset.
703 If $am is 0 (post-indexed), then the value is loaded from $base; if $am is 1 (pre-indexed)
704 then the value is loaded from $newaddr.
709 Same as G_INDEXED_LOAD except that the load performed is sign-extending, as with G_SEXTLOAD.
714 Same as G_INDEXED_LOAD except that the load performed is zero-extending, as with G_ZEXTLOAD.
719 Generic store. Expects a MachineMemOperand in addition to explicit
720 operands. If the stored value size is greater than the memory size,
721 the high bits are implicitly truncated. If this is a vector store, the
722 high elements are discarded (i.e. this does not function as a per-lane
723 vector, truncating store)
728 Combines a store with a GEP. See description of G_INDEXED_LOAD for indexing behaviour.
730 G_ATOMIC_CMPXCHG_WITH_SUCCESS
731 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
733 Generic atomic cmpxchg with internal success check. Expects a
734 MachineMemOperand in addition to explicit operands.
739 Generic atomic cmpxchg. Expects a MachineMemOperand in addition to explicit
742 G_ATOMICRMW_XCHG, G_ATOMICRMW_ADD, G_ATOMICRMW_SUB, G_ATOMICRMW_AND,
743 G_ATOMICRMW_NAND, G_ATOMICRMW_OR, G_ATOMICRMW_XOR, G_ATOMICRMW_MAX,
744 G_ATOMICRMW_MIN, G_ATOMICRMW_UMAX, G_ATOMICRMW_UMIN, G_ATOMICRMW_FADD,
745 G_ATOMICRMW_FSUB, G_ATOMICRMW_FMAX, G_ATOMICRMW_FMIN
746 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
748 Generic atomicrmw. Expects a MachineMemOperand in addition to explicit
754 Generic fence. The first operand is the memory ordering. The second operand is
757 See the LLVM LangRef entry on the '``fence'`` instruction for more details.
762 Generic memcpy. Expects two MachineMemOperands covering the store and load
763 respectively, in addition to explicit operands.
768 Generic inlined memcpy. Like G_MEMCPY, but it is guaranteed that this version
769 will not be lowered as a call to an external function. Currently the size
770 operand is required to evaluate as a constant (not an immediate), though that is
771 expected to change when llvm.memcpy.inline is taught to support dynamic sizes.
776 Generic memmove. Similar to G_MEMCPY, but the source and destination memory
777 ranges are allowed to overlap.
782 Generic memset. Expects a MachineMemOperand in addition to explicit operands.
787 Generic bzero. Expects a MachineMemOperand in addition to explicit operands.
795 Implement the φ node in the SSA graph representing the function.
799 %dst(s8) = G_PHI %src1(s8), %bb.<id1>, %src2(s8), %bb.<id2>
817 G_BRCOND %condition, %basicblock.<id>
826 G_BRINDIRECT %src(p0)
831 Indirect branch to jump table entry
835 G_BRJT %ptr(p0), %jti, %idx(s64)
840 Generates a pointer to the address of the jump table specified by the source
841 operand. The source operand is a jump table index.
842 G_JUMP_TABLE can be used in conjunction with G_BRJT to support jump table
843 codegen with GlobalISel.
847 %dst:_(p0) = G_JUMP_TABLE %jump-table.0
849 The above example generates a pointer to the source jump table index.
851 G_INVOKE_REGION_START
852 ^^^^^^^^^^^^^^^^^^^^^
854 A marker instruction that acts as a pseudo-terminator for regions of code that may
855 throw exceptions. Being a terminator, it prevents code from being inserted after
856 it during passes like legalization. This is needed because calls to exception
857 throw routines do not return, so no code that must be on an executable path must
858 be placed after throwing.
860 G_INTRINSIC, G_INTRINSIC_CONVERGENT
861 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
863 Call an intrinsic that has no side-effects.
865 The _CONVERGENT variant corresponds to an LLVM IR intrinsic marked `convergent`.
869 Unlike SelectionDAG, there is no _VOID variant. Both of these are permitted
870 to have zero, one, or multiple results.
872 G_INTRINSIC_W_SIDE_EFFECTS, G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS
873 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
875 Call an intrinsic that is considered to have unknown side-effects and as such
876 cannot be reordered across other side-effecting instructions.
878 The _CONVERGENT variant corresponds to an LLVM IR intrinsic marked `convergent`.
882 Unlike SelectionDAG, there is no _VOID variant. Both of these are permitted
883 to have zero, one, or multiple results.
893 I found no documentation for this instruction at the time of writing.
900 I found no documentation for this instruction at the time of writing.
908 Dynamically realigns the stack pointer to the specified size and alignment.
909 An alignment value of `0` or `1` means no specific alignment.
913 %8:_(p0) = G_DYN_STACKALLOC %7(s64), 32
918 These instructions do not correspond to any target instructions. They act as
919 hints for various combines.
921 G_ASSERT_SEXT, G_ASSERT_ZEXT
922 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
924 This signifies that the contents of a register were previously extended from a
927 The smaller type is denoted using an immediate operand. For scalars, this is the
928 width of the entire smaller type. For vectors, this is the width of the smaller
933 %x_was_zexted:_(s32) = G_ASSERT_ZEXT %x(s32), 16
934 %y_was_zexted:_(<2 x s32>) = G_ASSERT_ZEXT %y(<2 x s32>), 16
936 %z_was_sexted:_(s32) = G_ASSERT_SEXT %z(s32), 8
938 G_ASSERT_SEXT and G_ASSERT_ZEXT act like copies, albeit with some restrictions.
940 The source and destination registers must
943 - Belong to the same register class
944 - Belong to the same register bank
946 It should always be safe to
948 - Look through the source register
949 - Replace the destination register with the source register
955 G_CONSTANT_FOLD_BARRIER
956 ^^^^^^^^^^^^^^^^^^^^^^^
958 This operation is used as an opaque barrier to prevent constant folding. Combines
959 and other transformations should not look through this. These have no other
960 semantics and can be safely eliminated if a target chooses.