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)
72 Integer Extension and Truncation
73 --------------------------------
78 Extend the underlying scalar type of an operation, leaving the high bits
83 %1:_(s32) = G_ANYEXT %0:_(s16)
88 Sign extend the underlying scalar type of an operation, copying the sign bit
89 into the newly-created space.
93 %1:_(s32) = G_SEXT %0:_(s16)
98 Sign extend the value from an arbitrary bit position, copying the sign bit
99 into all bits above it. This is equivalent to a shl + ashr pair with an
100 appropriate shift amount. $sz is an immediate (MachineOperand::isImm()
101 returns true) to allow targets to have some bitwidths legal and others
102 lowered. This opcode is particularly useful if the target has sign-extension
103 instructions that are cheaper than the constituent shifts as the optimizer is
104 able to make decisions on whether it's better to hang on to the G_SEXT_INREG
105 or to lower it and optimize the individual shifts.
109 %1:_(s32) = G_SEXT_INREG %0:_(s32), 16
114 Zero extend the underlying scalar type of an operation, putting zero bits
115 into the newly-created space.
119 %1:_(s32) = G_ZEXT %0:_(s16)
124 Truncate the underlying scalar type of an operation. This is equivalent to
125 G_EXTRACT for scalar types, but acts elementwise on vectors.
129 %1:_(s16) = G_TRUNC %0:_(s32)
137 Convert an integer to a pointer.
141 %1:_(p0) = G_INTTOPTR %0:_(s32)
146 Convert a pointer to an integer.
150 %1:_(s32) = G_PTRTOINT %0:_(p0)
155 Reinterpret a value as a new type. This is usually done without
156 changing any bits but this is not always the case due a subtlety in the
157 definition of the :ref:`LLVM-IR Bitcast Instruction <i_bitcast>`. It
158 is allowed to bitcast between pointers with the same size, but
159 different address spaces.
163 %1:_(s64) = G_BITCAST %0:_(<2 x s32>)
168 Convert a pointer to an address space to a pointer to another address space.
172 %1:_(p1) = G_ADDRSPACE_CAST %0:_(p0)
176 :ref:`i_addrspacecast` doesn't mention what happens if the cast is simply
177 invalid (i.e. if the address spaces are disjoint).
185 Extract a register of the specified size, starting from the block given by
186 index. This will almost certainly be mapped to sub-register COPYs after
187 register banks have been selected.
191 %3:_(s32) = G_EXTRACT %2:_(s64), 32
196 Insert a smaller register into a larger one at the specified bit-index.
200 %2:_(s64) = G_INSERT %0:(_s64), %1:_(s32), 0
205 Concatenate multiple registers of the same size into a wider register.
206 The input operands are always ordered from lowest bits to highest:
210 %0:(s32) = G_MERGE_VALUES %bits_0_7:(s8), %bits_8_15:(s8),
211 %bits_16_23:(s8), %bits_24_31:(s8)
216 Extract multiple registers of the specified size, starting from blocks given by
217 indexes. This will almost certainly be mapped to sub-register COPYs after
218 register banks have been selected.
219 The output operands are always ordered from lowest bits to highest:
223 %bits_0_7:(s8), %bits_8_15:(s8),
224 %bits_16_23:(s8), %bits_24_31:(s8) = G_UNMERGE_VALUES %0:(s32)
229 Reverse the order of the bytes in a scalar.
233 %1:_(s32) = G_BSWAP %0:_(s32)
238 Reverse the order of the bits in a scalar.
242 %1:_(s32) = G_BITREVERSE %0:_(s32)
247 Extract a range of bits from a register.
249 The source operands are registers as follows:
252 - The least-significant bit for the extraction
253 - The width of the extraction
255 The least-significant bit (lsb) and width operands are in the range:
259 0 <= lsb < lsb + width <= source bitwidth, where all values are unsigned
261 G_SBFX sign-extends the result, while G_UBFX zero-extends the result.
265 ; Extract 5 bits starting at bit 1 from %x and store them in %a.
266 ; Sign-extend the result.
269 ; %x = 0...0000[10110]1 ---> %a = 1...111111[10110]
270 %lsb_one = G_CONSTANT i32 1
271 %width_five = G_CONSTANT i32 5
272 %a:_(s32) = G_SBFX %x, %lsb_one, %width_five
274 ; Extract 3 bits starting at bit 2 from %x and store them in %b. Zero-extend
278 ; %x = 1...11111[100]11 ---> %b = 0...00000[100]
279 %lsb_two = G_CONSTANT i32 2
280 %width_three = G_CONSTANT i32 3
281 %b:_(s32) = G_UBFX %x, %lsb_two, %width_three
286 G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR, G_SDIV, G_UDIV, G_SREM, G_UREM
287 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
289 These each perform their respective integer arithmetic on a scalar.
293 %dst:_(s32) = G_ADD %src0:_(s32), %src1:_(s32)
295 The above exmaple adds %src1 to %src0 and stores the result in %dst.
300 Perform integer division and remainder thereby producing two results.
304 %div:_(s32), %rem:_(s32) = G_SDIVREM %0:_(s32), %1:_(s32)
306 G_SADDSAT, G_UADDSAT, G_SSUBSAT, G_USUBSAT, G_SSHLSAT, G_USHLSAT
307 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
309 Signed and unsigned addition, subtraction and left shift with saturation.
313 %2:_(s32) = G_SADDSAT %0:_(s32), %1:_(s32)
315 G_SHL, G_LSHR, G_ASHR
316 ^^^^^^^^^^^^^^^^^^^^^
318 Shift the bits of a scalar left or right inserting zeros (sign-bit for G_ASHR).
323 Rotate the bits right (G_ROTR) or left (G_ROTL).
328 Perform integer comparison producing non-zero (true) or zero (false). It's
329 target specific whether a true value is 1, ~0U, or some other non-zero value.
334 Select between two values depending on a zero/non-zero value.
338 %5:_(s32) = G_SELECT %4(s1), %6, %2
343 Add a scalar offset in addressible units to a pointer. Addressible units are
344 typically bytes but this may vary between targets.
348 %1:_(p0) = G_PTR_ADD %0:_(p0), %1:_(s32)
352 There are currently no in-tree targets that use this with addressable units
358 Zero out an arbitrary mask of bits of a pointer. The mask type must be
359 an integer, and the number of vector elements must match for all
360 operands. This corresponds to `i_intr_llvm_ptrmask`.
364 %2:_(p0) = G_PTRMASK %0, %1
366 G_SMIN, G_SMAX, G_UMIN, G_UMAX
367 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
369 Take the minimum/maximum of two values.
373 %5:_(s32) = G_SMIN %6, %2
376 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
378 Take the absolute value of a signed integer. The absolute value of the minimum
379 negative value (e.g. the 8-bit value `0x80`) is defined to be itself.
385 G_UADDO, G_SADDO, G_USUBO, G_SSUBO, G_SMULO, G_UMULO
386 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
388 Perform the requested arithmetic and produce a carry output in addition to the
393 %3:_(s32), %4:_(s1) = G_UADDO %0, %1
395 G_UADDE, G_SADDE, G_USUBE, G_SSUBE
396 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
398 Perform the requested arithmetic and consume a carry input in addition to the
399 normal input. Also produce a carry output in addition to the normal result.
403 %4:_(s32), %5:_(s1) = G_UADDE %0, %1, %3:_(s1)
408 Multiply two numbers at twice the incoming bit width (signed) and return
409 the high half of the result.
413 %3:_(s32) = G_UMULH %0, %1
415 G_CTLZ, G_CTTZ, G_CTPOP
416 ^^^^^^^^^^^^^^^^^^^^^^^
418 Count leading zeros, trailing zeros, or number of set bits.
422 %2:_(s33) = G_CTLZ_ZERO_UNDEF %1
423 %2:_(s33) = G_CTTZ_ZERO_UNDEF %1
424 %2:_(s33) = G_CTPOP %1
426 G_CTLZ_ZERO_UNDEF, G_CTTZ_ZERO_UNDEF
427 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
429 Count leading zeros or trailing zeros. If the value is zero then the result is
434 %2:_(s33) = G_CTLZ_ZERO_UNDEF %1
435 %2:_(s33) = G_CTTZ_ZERO_UNDEF %1
437 Floating Point Operations
438 -------------------------
443 Perform floating point comparison producing non-zero (true) or zero
444 (false). It's target specific whether a true value is 1, ~0U, or some other
450 Floating point negation.
455 Convert a floating point value to a larger type.
460 Convert a floating point value to a narrower type.
462 G_FPTOSI, G_FPTOUI, G_SITOFP, G_UITOFP
463 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
465 Convert between integer and floating point.
470 Take the absolute value of a floating point value.
475 Copy the value of the first operand, replacing the sign bit with that of the
481 See :ref:`i_intr_llvm_canonicalize`.
486 Perform floating-point minimum on two values.
488 In the case where a single input is a NaN (either signaling or quiet),
489 the non-NaN input is returned.
491 The return value of (FMINNUM 0.0, -0.0) could be either 0.0 or -0.0.
496 Perform floating-point maximum on two values.
498 In the case where a single input is a NaN (either signaling or quiet),
499 the non-NaN input is returned.
501 The return value of (FMAXNUM 0.0, -0.0) could be either 0.0 or -0.0.
506 Perform floating-point minimum on two values, following the IEEE-754 2008
507 definition. This differs from FMINNUM in the handling of signaling NaNs. If one
508 input is a signaling NaN, returns a quiet NaN.
513 Perform floating-point maximum on two values, following the IEEE-754 2008
514 definition. This differs from FMAXNUM in the handling of signaling NaNs. If one
515 input is a signaling NaN, returns a quiet NaN.
520 NaN-propagating minimum that also treat -0.0 as less than 0.0. While
521 FMINNUM_IEEE follow IEEE 754-2008 semantics, FMINIMUM follows IEEE 754-2018
527 NaN-propagating maximum that also treat -0.0 as less than 0.0. While
528 FMAXNUM_IEEE follow IEEE 754-2008 semantics, FMAXIMUM follows IEEE 754-2018
531 G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FREM
532 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
534 Perform the specified floating point arithmetic.
539 Perform a fused multiply add (i.e. without the intermediate rounding step).
544 Perform a non-fused multiply add (i.e. with the intermediate rounding step).
549 Raise the first operand to the power of the second.
554 Calculate the base-e or base-2 exponential of a value
556 G_FLOG, G_FLOG2, G_FLOG10
557 ^^^^^^^^^^^^^^^^^^^^^^^^^
559 Calculate the base-e, base-2, or base-10 respectively.
561 G_FCEIL, G_FCOS, G_FSIN, G_FSQRT, G_FFLOOR, G_FRINT, G_FNEARBYINT
562 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
564 These correspond to the standard C functions of the same name.
569 Returns the operand rounded to the nearest integer not larger in magnitude than the operand.
574 Returns the operand rounded to the nearest integer.
579 Returns the source operand rounded to the nearest integer with ties away from
582 See the LLVM LangRef entry on '``llvm.lround.*'`` for details on behaviour.
586 %rounded_32:_(s32) = G_LROUND %round_me:_(s64)
587 %rounded_64:_(s64) = G_LLROUND %round_me:_(s64)
589 Vector Specific Operations
590 --------------------------
595 Concatenate two vectors to form a longer vector.
597 G_BUILD_VECTOR, G_BUILD_VECTOR_TRUNC
598 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
600 Create a vector from multiple scalar registers. No implicit
601 conversion is performed (i.e. the result element type must be the
602 same as all source operands)
604 The _TRUNC version truncates the larger operand types to fit the
605 destination vector elt type.
610 Insert an element into a vector
615 Extract an element from a vector
620 Concatenate two vectors and shuffle the elements according to the mask operand.
621 The mask operand should be an IR Constant which exactly matches the
622 corresponding mask for the IR shufflevector instruction.
624 Vector Reduction Operations
625 ---------------------------
627 These operations represent horizontal vector reduction, producing a scalar result.
629 G_VECREDUCE_SEQ_FADD, G_VECREDUCE_SEQ_FMUL
630 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
632 The SEQ variants perform reductions in sequential order. The first operand is
633 an initial scalar accumulator value, and the second operand is the vector to reduce.
635 G_VECREDUCE_FADD, G_VECREDUCE_FMUL
636 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
638 These reductions are relaxed variants which may reduce the elements in any order.
640 G_VECREDUCE_FMAX, G_VECREDUCE_FMIN
641 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
643 FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
648 GlobalISel-equivalent of the '``llvm.isnan``' intrinsic.
650 Returns a 1-bit scalar or vector of 1-bit scalar values. The result's contents
651 represent whether or not the source value is NaN.
655 %is_nan:_(s1) = G_ISNAN %check_me_for_nan
657 Integer/bitwise reductions
658 ^^^^^^^^^^^^^^^^^^^^^^^^^^
670 Integer reductions may have a result type larger than the vector element type.
671 However, the reduction is performed using the vector element type and the value
672 in the top bits is unspecified.
677 G_LOAD, G_SEXTLOAD, G_ZEXTLOAD
678 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
680 Generic load. Expects a MachineMemOperand in addition to explicit
681 operands. If the result size is larger than the memory size, the
682 high bits are undefined, sign-extended, or zero-extended respectively.
684 Only G_LOAD is valid if the result is a vector type. If the result is larger
685 than the memory size, the high elements are undefined (i.e. this is not a
686 per-element, vector anyextload)
691 Generic indexed load. Combines a GEP with a load. $newaddr is set to $base + $offset.
692 If $am is 0 (post-indexed), then the value is loaded from $base; if $am is 1 (pre-indexed)
693 then the value is loaded from $newaddr.
698 Same as G_INDEXED_LOAD except that the load performed is sign-extending, as with G_SEXTLOAD.
703 Same as G_INDEXED_LOAD except that the load performed is zero-extending, as with G_ZEXTLOAD.
708 Generic store. Expects a MachineMemOperand in addition to explicit
709 operands. If the stored value size is greater than the memory size,
710 the high bits are implicitly truncated. If this is a vector store, the
711 high elements are discarded (i.e. this does not function as a per-lane
712 vector, truncating store)
717 Combines a store with a GEP. See description of G_INDEXED_LOAD for indexing behaviour.
719 G_ATOMIC_CMPXCHG_WITH_SUCCESS
720 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
722 Generic atomic cmpxchg with internal success check. Expects a
723 MachineMemOperand in addition to explicit operands.
728 Generic atomic cmpxchg. Expects a MachineMemOperand in addition to explicit
731 G_ATOMICRMW_XCHG, G_ATOMICRMW_ADD, G_ATOMICRMW_SUB, G_ATOMICRMW_AND, G_ATOMICRMW_NAND, G_ATOMICRMW_OR, G_ATOMICRMW_XOR, G_ATOMICRMW_MAX, G_ATOMICRMW_MIN, G_ATOMICRMW_UMAX, G_ATOMICRMW_UMIN, G_ATOMICRMW_FADD, G_ATOMICRMW_FSUB
732 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
734 Generic atomicrmw. Expects a MachineMemOperand in addition to explicit
742 I couldn't find any documentation on this at the time of writing.
747 Generic memcpy. Expects two MachineMemOperands covering the store and load
748 respectively, in addition to explicit operands.
753 Generic inlined memcpy. Like G_MEMCPY, but it is guaranteed that this version
754 will not be lowered as a call to an external function. Currently the size
755 operand is required to evaluate as a constant (not an immediate), though that is
756 expected to change when llvm.memcpy.inline is taught to support dynamic sizes.
761 Generic memmove. Similar to G_MEMCPY, but the source and destination memory
762 ranges are allowed to overlap.
767 Generic memset. Expects a MachineMemOperand in addition to explicit operands.
772 Generic bzero. Expects a MachineMemOperand in addition to explicit operands.
780 Implement the φ node in the SSA graph representing the function.
784 %dst(s8) = G_PHI %src1(s8), %bb.<id1>, %src2(s8), %bb.<id2>
802 G_BRCOND %condition, %basicblock.<id>
811 G_BRINDIRECT %src(p0)
816 Indirect branch to jump table entry
820 G_BRJT %ptr(p0), %jti, %idx(s64)
827 I found no documentation for this instruction at the time of writing.
829 G_INTRINSIC, G_INTRINSIC_W_SIDE_EFFECTS
830 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
834 The _W_SIDE_EFFECTS version is considered to have unknown side-effects and
835 as such cannot be reordered across other side-effecting instructions.
839 Unlike SelectionDAG, there is no _VOID variant. Both of these are permitted
840 to have zero, one, or multiple results.
850 I found no documentation for this instruction at the time of writing.
857 I found no documentation for this instruction at the time of writing.
865 Dynamically realigns the stack pointer to the specified size and alignment.
866 An alignment value of `0` or `1` means no specific alignment.
870 %8:_(p0) = G_DYN_STACKALLOC %7(s64), 32
875 These instructions do not correspond to any target instructions. They act as
876 hints for various combines.
878 G_ASSERT_SEXT, G_ASSERT_ZEXT
879 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
881 This signifies that the contents of a register were previously extended from a
884 The smaller type is denoted using an immediate operand. For scalars, this is the
885 width of the entire smaller type. For vectors, this is the width of the smaller
890 %x_was_zexted:_(s32) = G_ASSERT_ZEXT %x(s32), 16
891 %y_was_zexted:_(<2 x s32>) = G_ASSERT_ZEXT %y(<2 x s32>), 16
893 %z_was_sexted:_(s32) = G_ASSERT_SEXT %z(s32), 8
895 G_ASSERT_SEXT and G_ASSERT_ZEXT act like copies, albeit with some restrictions.
897 The source and destination registers must
900 - Belong to the same register class
901 - Belong to the same register bank
903 It should always be safe to
905 - Look through the source register
906 - Replace the destination register with the source register