+
+
+
+
+
Binary operators are used to do most of the computation in a
+program. They require two operands, execute an operation on them, and
+produce a single value. The operands might represent
+multiple data, as is the case with the vector data type.
+The result value of a binary operator is not
+necessarily the same type as its operands.
+
There are several different binary operators:
+
+
+
+
+
Syntax:
+
<result> = add <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'add' instruction returns the sum of its two operands.
+
Arguments:
+
The two arguments to the 'add' instruction must be either integer or floating point values.
+ This instruction can also take vector versions of the values.
+Both arguments must have identical types.
+
Semantics:
+
The value produced is the integer or floating point sum of the two
+operands.
+
Example:
+
<result> = add i32 4, %var ; yields {i32}:result = 4 + %var
+
+
+
+
+
+
Syntax:
+
<result> = sub <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'sub' instruction returns the difference of its two
+operands.
+
Note that the 'sub' instruction is used to represent the 'neg'
+instruction present in most other intermediate representations.
+
Arguments:
+
The two arguments to the 'sub' instruction must be either integer or floating point
+values.
+This instruction can also take vector versions of the values.
+Both arguments must have identical types.
+
Semantics:
+
The value produced is the integer or floating point difference of
+the two operands.
+
Example:
+
<result> = sub i32 4, %var ; yields {i32}:result = 4 - %var
+ <result> = sub i32 0, %val ; yields {i32}:result = -%var
+
+
+
+
+
+
Syntax:
+
<result> = mul <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'mul' instruction returns the product of its two
+operands.
+
Arguments:
+
The two arguments to the 'mul' instruction must be either integer or floating point
+values.
+This instruction can also take vector versions of the values.
+Both arguments must have identical types.
+
Semantics:
+
The value produced is the integer or floating point product of the
+two operands.
+
Because the operands are the same width, the result of an integer
+multiplication is the same whether the operands should be deemed unsigned or
+signed.
+
Example:
+
<result> = mul i32 4, %var ; yields {i32}:result = 4 * %var
+
+
+
+
+
+
Syntax:
+
<result> = udiv <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'udiv' instruction returns the quotient of its two
+operands.
+
Arguments:
+
The two arguments to the 'udiv' instruction must be
+integer values. Both arguments must have identical
+types. This instruction can also take vector versions
+of the values in which case the elements must be integers.
+
Semantics:
+
The value produced is the unsigned integer quotient of the two operands. This
+instruction always performs an unsigned division operation, regardless of
+whether the arguments are unsigned or not.
+
Example:
+
<result> = udiv i32 4, %var ; yields {i32}:result = 4 / %var
+
+
+
+
+
+
Syntax:
+
<result> = sdiv <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'sdiv' instruction returns the quotient of its two
+operands.
+
Arguments:
+
The two arguments to the 'sdiv' instruction must be
+integer values. Both arguments must have identical
+types. This instruction can also take vector versions
+of the values in which case the elements must be integers.
+
Semantics:
+
The value produced is the signed integer quotient of the two operands. This
+instruction always performs a signed division operation, regardless of whether
+the arguments are signed or not.
+
Example:
+
<result> = sdiv i32 4, %var ; yields {i32}:result = 4 / %var
+
+
+
+
+
+
Syntax:
+
<result> = fdiv <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'fdiv' instruction returns the quotient of its two
+operands.
+
Arguments:
+
The two arguments to the 'div' instruction must be
+floating point values. Both arguments must have
+identical types. This instruction can also take vector
+versions of the values in which case the elements must be floating point.
+
Semantics:
+
The value produced is the floating point quotient of the two operands.
+
Example:
+
<result> = fdiv float 4.0, %var ; yields {float}:result = 4.0 / %var
+
+
+
+
+
+
Syntax:
+
<result> = urem <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'urem' instruction returns the remainder from the
+unsigned division of its two arguments.
+
Arguments:
+
The two arguments to the 'urem' instruction must be
+integer values. Both arguments must have identical
+types.
+
Semantics:
+
This instruction returns the unsigned integer remainder of a division.
+This instruction always performs an unsigned division to get the remainder,
+regardless of whether the arguments are unsigned or not.
+
Example:
+
<result> = urem i32 4, %var ; yields {i32}:result = 4 % %var
+
+
+
+
+
+
+
Syntax:
+
<result> = srem <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'srem' instruction returns the remainder from the
+signed division of its two operands.
+
Arguments:
+
The two arguments to the 'srem' instruction must be
+integer values. Both arguments must have identical
+types.
+
Semantics:
+
This instruction returns the remainder of a division (where the result
+has the same sign as the dividend, var1), not the modulo
+operator (where the result has the same sign as the divisor, var2) of
+a value. For more information about the difference, see The
+Math Forum. For a table of how this is implemented in various languages,
+please see
+Wikipedia: modulo operation.
+
Example:
+
<result> = srem i32 4, %var ; yields {i32}:result = 4 % %var
+
+
+
+
+
+
+
Syntax:
+
<result> = frem <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'frem' instruction returns the remainder from the
+division of its two operands.
+
Arguments:
+
The two arguments to the 'frem' instruction must be
+floating point values. Both arguments must have
+identical types.
+
Semantics:
+
This instruction returns the remainder of a division.
+
Example:
+
<result> = frem float 4.0, %var ; yields {float}:result = 4.0 % %var
+
+
+
+
+
+
+
Bitwise binary operators are used to do various forms of
+bit-twiddling in a program. They are generally very efficient
+instructions and can commonly be strength reduced from other
+instructions. They require two operands, execute an operation on them,
+and produce a single value. The resulting value of the bitwise binary
+operators is always the same type as its first operand.
+
+
+
+
+
+
Syntax:
+
<result> = shl <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'shl' instruction returns the first operand shifted to
+the left a specified number of bits.
+
Arguments:
+
Both arguments to the 'shl' instruction must be the same integer type.
+
Semantics:
+
The value produced is var1 * 2var2.
+
Example:
+ <result> = shl i32 4, %var ; yields {i32}: 4 << %var
+ <result> = shl i32 4, 2 ; yields {i32}: 16
+ <result> = shl i32 1, 10 ; yields {i32}: 1024
+
+
+
+
+
+
Syntax:
+
<result> = lshr <ty> <var1>, <var2> ; yields {ty}:result
+
+
+
Overview:
+
The 'lshr' instruction (logical shift right) returns the first
+operand shifted to the right a specified number of bits.
+
+
Arguments:
+
Both arguments to the 'lshr' instruction must be the same
+integer type.
+
+
Semantics:
+
This instruction always performs a logical shift right operation. The most
+significant bits of the result will be filled with zero bits after the
+shift.
+
+
Example:
+
+ <result> = lshr i32 4, 1 ; yields {i32}:result = 2
+ <result> = lshr i32 4, 2 ; yields {i32}:result = 1
+ <result> = lshr i8 4, 3 ; yields {i8}:result = 0
+ <result> = lshr i8 -2, 1 ; yields {i8}:result = 0x7FFFFFFF
+
+
+
+
+
+
+
+
Syntax:
+
<result> = ashr <ty> <var1>, <var2> ; yields {ty}:result
+
+
+
Overview:
+
The 'ashr' instruction (arithmetic shift right) returns the first
+operand shifted to the right a specified number of bits.
+
+
Arguments:
+
Both arguments to the 'ashr' instruction must be the same
+integer type.
+
+
Semantics:
+
This instruction always performs an arithmetic shift right operation,
+The most significant bits of the result will be filled with the sign bit
+of var1.
+
+
Example:
+
+ <result> = ashr i32 4, 1 ; yields {i32}:result = 2
+ <result> = ashr i32 4, 2 ; yields {i32}:result = 1
+ <result> = ashr i8 4, 3 ; yields {i8}:result = 0
+ <result> = ashr i8 -2, 1 ; yields {i8}:result = -1
+
+
+
+
+
+
+
Syntax:
+
<result> = and <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'and' instruction returns the bitwise logical and of
+its two operands.
+
Arguments:
+
The two arguments to the 'and' instruction must be integer values. Both arguments must have
+identical types.
+
Semantics:
+
The truth table used for the 'and' instruction is:
+
+
+
+
+
+ In0 |
+ In1 |
+ Out |
+
+
+ 0 |
+ 0 |
+ 0 |
+
+
+ 0 |
+ 1 |
+ 0 |
+
+
+ 1 |
+ 0 |
+ 0 |
+
+
+ 1 |
+ 1 |
+ 1 |
+
+
+
+
+
Example:
+
<result> = and i32 4, %var ; yields {i32}:result = 4 & %var
+ <result> = and i32 15, 40 ; yields {i32}:result = 8
+ <result> = and i32 4, 8 ; yields {i32}:result = 0
+
+
+
+
+
+
Syntax:
+
<result> = or <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'or' instruction returns the bitwise logical inclusive
+or of its two operands.
+
Arguments:
+
The two arguments to the 'or' instruction must be integer values. Both arguments must have
+identical types.
+
Semantics:
+
The truth table used for the 'or' instruction is:
+
+
+
+
+
+ In0 |
+ In1 |
+ Out |
+
+
+ 0 |
+ 0 |
+ 0 |
+
+
+ 0 |
+ 1 |
+ 1 |
+
+
+ 1 |
+ 0 |
+ 1 |
+
+
+ 1 |
+ 1 |
+ 1 |
+
+
+
+
+
Example:
+
<result> = or i32 4, %var ; yields {i32}:result = 4 | %var
+ <result> = or i32 15, 40 ; yields {i32}:result = 47
+ <result> = or i32 4, 8 ; yields {i32}:result = 12
+
+
+
+
+
+
Syntax:
+
<result> = xor <ty> <var1>, <var2> ; yields {ty}:result
+
+
Overview:
+
The 'xor' instruction returns the bitwise logical exclusive
+or of its two operands. The xor is used to implement the
+"one's complement" operation, which is the "~" operator in C.
+
Arguments:
+
The two arguments to the 'xor' instruction must be integer values. Both arguments must have
+identical types.
+
Semantics:
+
The truth table used for the 'xor' instruction is:
+
+
+
+
+
+ In0 |
+ In1 |
+ Out |
+
+
+ 0 |
+ 0 |
+ 0 |
+
+
+ 0 |
+ 1 |
+ 1 |
+
+
+ 1 |
+ 0 |
+ 1 |
+
+
+ 1 |
+ 1 |
+ 0 |
+
+
+
+
+
+
Example:
+
<result> = xor i32 4, %var ; yields {i32}:result = 4 ^ %var
+ <result> = xor i32 15, 40 ; yields {i32}:result = 39
+ <result> = xor i32 4, 8 ; yields {i32}:result = 12
+ <result> = xor i32 %V, -1 ; yields {i32}:result = ~%V
+
+
+
+
+
+
+
+
+
LLVM supports several instructions to represent vector operations in a
+target-independent manner. This instructions cover the element-access and
+vector-specific operations needed to process vectors effectively. While LLVM
+does directly support these vector operations, many sophisticated algorithms
+will want to use target-specific intrinsics to take full advantage of a specific
+target.
+
+
+
+
+
+
+
+
+
Syntax:
+
+
+ <result> = extractelement <n x <ty>> <val>, i32 <idx> ; yields <ty>
+
+
+
Overview:
+
+
+The 'extractelement' instruction extracts a single scalar
+element from a vector at a specified index.
+
+
+
+
Arguments:
+
+
+The first operand of an 'extractelement' instruction is a
+value of vector type. The second operand is
+an index indicating the position from which to extract the element.
+The index may be a variable.
+
+
Semantics:
+
+
+The result is a scalar of the same type as the element type of
+val. Its value is the value at position idx of
+val. If idx exceeds the length of val, the
+results are undefined.
+
+
+
Example:
+
+
+ %result = extractelement <4 x i32> %vec, i32 0 ; yields i32
+
+
+
+
+
+
+
+
+
+
Syntax:
+
+
+ <result> = insertelement <n x <ty>> <val>, <ty> <elt>, i32 <idx> ; yields <n x <ty>>
+
+
+
Overview:
+
+
+The 'insertelement' instruction inserts a scalar
+element into a vector at a specified index.
+
+
+
+
Arguments:
+
+
+The first operand of an 'insertelement' instruction is a
+value of vector type. The second operand is a
+scalar value whose type must equal the element type of the first
+operand. The third operand is an index indicating the position at
+which to insert the value. The index may be a variable.
+
+
Semantics:
+
+
+The result is a vector of the same type as val. Its
+element values are those of val except at position
+idx, where it gets the value elt. If idx
+exceeds the length of val, the results are undefined.
+
+
+
Example:
+
+
+ %result = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
+
+
+
+
+
+
+
+
+
Syntax:
+
+
+ <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <n x i32> <mask> ; yields <n x <ty>>
+
+
+
Overview:
+
+
+The 'shufflevector' instruction constructs a permutation of elements
+from two input vectors, returning a vector of the same type.
+
+
+
Arguments:
+
+
+The first two operands of a 'shufflevector' instruction are vectors
+with types that match each other and types that match the result of the
+instruction. The third argument is a shuffle mask, which has the same number
+of elements as the other vector type, but whose element type is always 'i32'.
+
+
+
+The shuffle mask operand is required to be a constant vector with either
+constant integer or undef values.
+
+
+
Semantics:
+
+
+The elements of the two input vectors are numbered from left to right across
+both of the vectors. The shuffle mask operand specifies, for each element of
+the result vector, which element of the two input registers the result element
+gets. The element selector may be undef (meaning "don't care") and the second
+operand may be undef if performing a shuffle from only one vector.
+
+
+
Example:
+
+
+ %result = shufflevector <4 x i32> %v1, <4 x i32> %v2,
+ <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
+ %result = shufflevector <4 x i32> %v1, <4 x i32> undef,
+ <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
+
+
+
+
+
+
+
+
+
+
A key design point of an SSA-based representation is how it
+represents memory. In LLVM, no memory locations are in SSA form, which
+makes things very simple. This section describes how to read, write,
+allocate, and free memory in LLVM.
+
+
+
+
+
+
+
+
+
Syntax:
+
+
+ <result> = malloc <type>[, i32 <NumElements>][, align <alignment>] ; yields {type*}:result
+
+
+
Overview:
+
+
The 'malloc' instruction allocates memory from the system
+heap and returns a pointer to it.
+
+
Arguments:
+
+
The 'malloc' instruction allocates
+sizeof(<type>)*NumElements
+bytes of memory from the operating system and returns a pointer of the
+appropriate type to the program. If "NumElements" is specified, it is the
+number of elements allocated. If an alignment is specified, the value result
+of the allocation is guaranteed to be aligned to at least that boundary. If
+not specified, or if zero, the target can choose to align the allocation on any
+convenient boundary.
+
+
'type' must be a sized type.
+
+
Semantics:
+
+
Memory is allocated using the system "malloc" function, and
+a pointer is returned.
+
+
Example:
+
+
+ %array = malloc [4 x i8 ] ; yields {[%4 x i8]*}:array
+
+ %size = add i32 2, 2 ; yields {i32}:size = i32 4
+ %array1 = malloc i8, i32 4 ; yields {i8*}:array1
+ %array2 = malloc [12 x i8], i32 %size ; yields {[12 x i8]*}:array2
+ %array3 = malloc i32, i32 4, align 1024 ; yields {i32*}:array3
+ %array4 = malloc i32, align 1024 ; yields {i32*}:array4
+
+
+
+
+
+
+
+
+
Syntax:
+
+
+ free <type> <value> ; yields {void}
+
+
+
Overview:
+
+
The 'free' instruction returns memory back to the unused
+memory heap to be reallocated in the future.
+
+
Arguments:
+
+
'value' shall be a pointer value that points to a value
+that was allocated with the 'malloc'
+instruction.
+
+
Semantics:
+
+
Access to the memory pointed to by the pointer is no longer defined
+after this instruction executes.
+
+
Example:
+
+
+ %array = malloc [4 x i8] ; yields {[4 x i8]*}:array
+ free [4 x i8]* %array
+
+
+
+
+
+
+
+
+
Syntax:
+
+
+ <result> = alloca <type>[, i32 <NumElements>][, align <alignment>] ; yields {type*}:result
+
+
+
Overview:
+
+
The 'alloca' instruction allocates memory on the current
+stack frame of the procedure that is live until the current function
+returns to its caller.
+
+
Arguments:
+
+
The 'alloca' instruction allocates sizeof(<type>)*NumElements
+bytes of memory on the runtime stack, returning a pointer of the
+appropriate type to the program. If "NumElements" is specified, it is the
+number of elements allocated. If an alignment is specified, the value result
+of the allocation is guaranteed to be aligned to at least that boundary. If
+not specified, or if zero, the target can choose to align the allocation on any
+convenient boundary.
+
+
'type' may be any sized type.
+
+
Semantics:
+
+
Memory is allocated; a pointer is returned. 'alloca'd
+memory is automatically released when the function returns. The 'alloca'
+instruction is commonly used to represent automatic variables that must
+have an address available. When the function returns (either with the ret or unwind
+instructions), the memory is reclaimed.
+
+
Example:
+
+
+ %ptr = alloca i32 ; yields {i32*}:ptr
+ %ptr = alloca i32, i32 4 ; yields {i32*}:ptr
+ %ptr = alloca i32, i32 4, align 1024 ; yields {i32*}:ptr
+ %ptr = alloca i32, align 1024 ; yields {i32*}:ptr
+
+
+
+
+
+
+
Syntax:
+
<result> = load <ty>* <pointer>
<result> = volatile load <ty>* <pointer>
+
Overview:
+
The 'load' instruction is used to read from memory.
+
Arguments:
+
The argument to the 'load' instruction specifies the memory
+address from which to load. The pointer must point to a first class type. If the load is
+marked as volatile, then the optimizer is not allowed to modify
+the number or order of execution of this load with other
+volatile load and store
+instructions.
+
Semantics:
+
The location of memory pointed to is loaded.
+
Examples:
+
%ptr = alloca i32 ; yields {i32*}:ptr
+ store i32 3, i32* %ptr ; yields {void}
+ %val = load i32* %ptr ; yields {i32}:val = i32 3
+
+
+
+
+
+
Syntax:
+
store <ty> <value>, <ty>* <pointer> ; yields {void}
+ volatile store <ty> <value>, <ty>* <pointer> ; yields {void}
+
+
Overview:
+
The 'store' instruction is used to write to memory.
+
Arguments:
+
There are two arguments to the 'store' instruction: a value
+to store and an address in which to store it. The type of the '<pointer>'
+operand must be a pointer to the type of the '<value>'
+operand. If the store is marked as volatile, then the
+optimizer is not allowed to modify the number or order of execution of
+this store with other volatile load and store instructions.
+
Semantics:
+
The contents of memory are updated to contain '<value>'
+at the location specified by the '<pointer>' operand.
+
Example:
+
%ptr = alloca i32 ; yields {i32*}:ptr
+ store i32 3, i32* %ptr ; yields {void}
+ %val = load i32* %ptr ; yields {i32}:val = i32 3
+
+
+
+
+
+
+
+
Syntax:
+
+ <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}*
+
+
+
Overview:
+
+
+The 'getelementptr' instruction is used to get the address of a
+subelement of an aggregate data structure.
+
+
Arguments:
+
+
This instruction takes a list of integer operands that indicate what
+elements of the aggregate object to index to. The actual types of the arguments
+provided depend on the type of the first pointer argument. The
+'getelementptr' instruction is used to index down through the type
+levels of a structure or to a specific index in an array. When indexing into a
+structure, only i32 integer constants are allowed. When indexing
+into an array or pointer, only integers of 32 or 64 bits are allowed, and will
+be sign extended to 64-bit values.
+
+
For example, let's consider a C code fragment and how it gets
+compiled to LLVM:
+
+
+ struct RT {
+ char A;
+ i32 B[10][20];
+ char C;
+ };
+ struct ST {
+ i32 X;
+ double Y;
+ struct RT Z;
+ };
+
+ define i32 *foo(struct ST *s) {
+ return &s[1].Z.B[5][13];
+ }
+
+
+
The LLVM code generated by the GCC frontend is:
+
+
+ %RT = type { i8 , [10 x [20 x i32]], i8 }
+ %ST = type { i32, double, %RT }
+
+ implementation
+
+ define i32* %foo(%ST* %s) {
+ entry:
+ %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
+ ret i32* %reg
+ }
+
+
+
Semantics:
+
+
The index types specified for the 'getelementptr' instruction depend
+on the pointer type that is being indexed into. Pointer
+and array types can use a 32-bit or 64-bit
+integer type but the value will always be sign extended
+to 64-bits. Structure types, require i32
+constants.
+
+
In the example above, the first index is indexing into the '%ST*'
+type, which is a pointer, yielding a '%ST' = '{ i32, double, %RT
+}' type, a structure. The second index indexes into the third element of
+the structure, yielding a '%RT' = '{ i8 , [10 x [20 x i32]],
+i8 }' type, another structure. The third index indexes into the second
+element of the structure, yielding a '[10 x [20 x i32]]' type, an
+array. The two dimensions of the array are subscripted into, yielding an
+'i32' type. The 'getelementptr' instruction returns a pointer
+to this element, thus computing a value of 'i32*' type.
+
+
Note that it is perfectly legal to index partially through a
+structure, returning a pointer to an inner element. Because of this,
+the LLVM code for the given testcase is equivalent to:
+
+
+ define i32* %foo(%ST* %s) {
+ %t1 = getelementptr %ST* %s, i32 1 ; yields %ST*:%t1
+ %t2 = getelementptr %ST* %t1, i32 0, i32 2 ; yields %RT*:%t2
+ %t3 = getelementptr %RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3
+ %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4
+ %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5
+ ret i32* %t5
+ }
+
+
+
Note that it is undefined to access an array out of bounds: array and
+pointer indexes must always be within the defined bounds of the array type.
+The one exception for this rules is zero length arrays. These arrays are
+defined to be accessible as variable length arrays, which requires access
+beyond the zero'th element.
+
+
The getelementptr instruction is often confusing. For some more insight
+into how it works, see the getelementptr
+FAQ.
+
+
Example:
+
+
+ ; yields [12 x i8]*:aptr
+ %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1
+
+
+
+
+
+
+
The instructions in this category are the conversion instructions (casting)
+which all take a single operand and a type. They perform various bit conversions
+on the operand.
+
+
+
+
+
+
+
Syntax:
+
+ <result> = trunc <ty> <value> to <ty2> ; yields ty2
+
+
+
Overview:
+
+The 'trunc' instruction truncates its operand to the type ty2.
+
+
+
Arguments:
+
+The 'trunc' instruction takes a value to trunc, which must
+be an integer type, and a type that specifies the size
+and type of the result, which must be an integer
+type. The bit size of value must be larger than the bit size of
+ty2. Equal sized types are not allowed.
+
+
Semantics:
+
+The 'trunc' instruction truncates the high order bits in value
+and converts the remaining bits to ty2. Since the source size must be
+larger than the destination size, trunc cannot be a no-op cast.
+It will always truncate bits.
+
+
Example:
+
+ %X = trunc i32 257 to i8 ; yields i8:1
+ %Y = trunc i32 123 to i1 ; yields i1:true
+ %Y = trunc i32 122 to i1 ; yields i1:false
+
+
+
+
+
+
+
+
Syntax:
+
+ <result> = zext <ty> <value> to <ty2> ; yields ty2
+
+
+
Overview:
+
The 'zext' instruction zero extends its operand to type
+ty2.
+
+
+
Arguments:
+
The 'zext' instruction takes a value to cast, which must be of
+integer type, and a type to cast it to, which must
+also be of integer type. The bit size of the
+value must be smaller than the bit size of the destination type,
+ty2.
+
+
Semantics:
+
The zext fills the high order bits of the value with zero
+bits until it reaches the size of the destination type, ty2. When the
+the operand and the type are the same size, no bit filling is done and the
+cast is considered a no-op cast because no bits change (only the type
+changes).
+
+
When zero extending from i1, the result will always be either 0 or 1.
+
+
Example:
+
+ %X = zext i32 257 to i64 ; yields i64:257
+ %Y = zext i1 true to i32 ; yields i32:1
+
+
+
+
+
+
+
+
Syntax:
+
+ <result> = sext <ty> <value> to <ty2> ; yields ty2
+
+
+
Overview:
+
The 'sext' sign extends value to the type ty2.
+
+
Arguments:
+
+The 'sext' instruction takes a value to cast, which must be of
+integer type, and a type to cast it to, which must
+also be of integer type. The bit size of the
+value must be smaller than the bit size of the destination type,
+ty2.
+
+
Semantics:
+
+The 'sext' instruction performs a sign extension by copying the sign
+bit (highest order bit) of the value until it reaches the bit size of
+the type ty2. When the the operand and the type are the same size,
+no bit filling is done and the cast is considered a no-op cast because
+no bits change (only the type changes).
+
+
When sign extending from i1, the extension always results in -1 or 0.
+
+
Example:
+
+ %X = sext i8 -1 to i16 ; yields i16 :65535
+ %Y = sext i1 true to i32 ; yields i32:-1
+
+
+
+
+
+
+
+
+
Syntax:
+
+
+ <result> = fptrunc <ty> <value> to <ty2> ; yields ty2
+
+
+
Overview:
+
The 'fptrunc' instruction truncates value to type
+ty2.
+
+
+
Arguments:
+
The 'fptrunc' instruction takes a floating
+ point value to cast and a floating point type to
+cast it to. The size of value must be larger than the size of
+ty2. This implies that fptrunc cannot be used to make a
+no-op cast.
+
+
Semantics:
+
The 'fptrunc' instruction truncates a value from a larger
+floating point type to a smaller
+floating point type. If the value cannot fit within
+the destination type, ty2, then the results are undefined.
+
+
Example:
+
+ %X = fptrunc double 123.0 to float ; yields float:123.0
+ %Y = fptrunc double 1.0E+300 to float ; yields undefined
+
+
+
+
+
+
+
+
Syntax:
+
+ <result> = fpext <ty> <value> to <ty2> ; yields ty2
+
+
+
Overview:
+
The 'fpext' extends a floating point value to a larger
+floating point value.
+
+
Arguments:
+
The 'fpext' instruction takes a
+floating point value to cast,
+and a floating point type to cast it to. The source
+type must be smaller than the destination type.
+
+
Semantics:
+
The 'fpext' instruction extends the value from a smaller
+floating point type to a larger
+floating point type. The fpext cannot be
+used to make a no-op cast because it always changes bits. Use
+bitcast to make a no-op cast for a floating point cast.
+
+
Example:
+
+ %X = fpext float 3.1415 to double ; yields double:3.1415
+ %Y = fpext float 1.0 to float ; yields float:1.0 (no-op)
+
+
+
+
+
+
+
+
Syntax:
+
+ <result> = fp2uint <ty> <value> to <ty2> ; yields ty2
+
+
+
Overview:
+
The 'fp2uint' converts a floating point value to its
+unsigned integer equivalent of type ty2.
+
+
+
Arguments:
+
The 'fp2uint' instruction takes a value to cast, which must be a
+floating point value, and a type to cast it to, which
+must be an integer type.
+
+
Semantics:
+
The 'fp2uint' instruction converts its
+floating point operand into the nearest (rounding
+towards zero) unsigned integer value. If the value cannot fit in ty2,
+the results are undefined.
+
+
When converting to i1, the conversion is done as a comparison against
+zero. If the value was zero, the i1 result will be false.
+If the value was non-zero, the i1 result will be true.
+
+
Example:
+
+ %X = fp2uint double 123.0 to i32 ; yields i32:123
+ %Y = fp2uint float 1.0E+300 to i1 ; yields i1:true
+ %X = fp2uint float 1.04E+17 to i8 ; yields undefined:1
+
+
+
+
+
+
+
+
Syntax:
+
+ <result> = fptosi <ty> <value> to <ty2> ; yields ty2
+
+
+
Overview:
+
The 'fptosi' instruction converts
+floating point value to type ty2.
+
+
+
+
Arguments:
+
The 'fptosi' instruction takes a value to cast, which must be a
+floating point value, and a type to cast it to, which
+must also be an integer type.
+
+
Semantics:
+
The 'fptosi' instruction converts its
+floating point operand into the nearest (rounding
+towards zero) signed integer value. If the value cannot fit in ty2,
+the results are undefined.
+
+
When converting to i1, the conversion is done as a comparison against
+zero. If the value was zero, the i1 result will be false.
+If the value was non-zero, the i1 result will be true.
+
+
Example:
+
+ %X = fptosi double -123.0 to i32 ; yields i32:-123
+ %Y = fptosi float 1.0E-247 to i1 ; yields i1:true
+ %X = fptosi float 1.04E+17 to i8 ; yields undefined:1
+
+
+
+
+
+
+
+
Syntax:
+
+ <result> = uitofp <ty> <value> to <ty2> ; yields ty2
+
+
+
Overview:
+
The 'uitofp' instruction regards value as an unsigned
+integer and converts that value to the ty2 type.
+
+
+
Arguments:
+
The 'uitofp' instruction takes a value to cast, which must be an
+integer value, and a type to cast it to, which must
+be a floating point type.
+
+
Semantics:
+
The 'uitofp' instruction interprets its operand as an unsigned
+integer quantity and converts it to the corresponding floating point value. If
+the value cannot fit in the floating point value, the results are undefined.
+
+
+
Example:
+
+ %X = uitofp i32 257 to float ; yields float:257.0
+ %Y = uitofp i8 -1 to double ; yields double:255.0
+
+
+
+
+
+
+
+
Syntax:
+
+ <result> = sitofp <ty> <value> to <ty2> ; yields ty2
+
+
+
Overview:
+
The 'sitofp' instruction regards value as a signed
+integer and converts that value to the ty2 type.
+
+
Arguments:
+
The 'sitofp' instruction takes a value to cast, which must be an
+integer value, and a type to cast it to, which must be
+a floating point type.
+
+
Semantics:
+
The 'sitofp' instruction interprets its operand as a signed
+integer quantity and converts it to the corresponding floating point value. If
+the value cannot fit in the floating point value, the results are undefined.
+
+
Example:
+
+ %X = sitofp i32 257 to float ; yields float:257.0
+ %Y = sitofp i8 -1 to double ; yields double:-1.0
+
+
+
+
+
+
+
+
Syntax:
+
+ <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2
+
+
+
Overview:
+
The 'ptrtoint' instruction converts the pointer value to
+the integer type ty2.
+
+
Arguments:
+
The 'ptrtoint' instruction takes a value to cast, which
+must be a pointer value, and a type to cast it to
+ty2, which must be an integer type.
+
+
Semantics:
+
The 'ptrtoint' instruction converts value to integer type
+ty2 by interpreting the pointer value as an integer and either
+truncating or zero extending that value to the size of the integer type. If
+value is smaller than ty2 then a zero extension is done. If
+value is larger than ty2 then a truncation is done. If they
+are the same size, then nothing is done (no-op cast).
+
+
Example:
+
+ %X = ptrtoint i32* %X to i8 ; yields truncation on 32-bit
+ %Y = ptrtoint i32* %x to i64 ; yields zero extend on 32-bit
+
+
+
+
+
+
Syntax:
- <result> = mul <ty> <var1>, <var2> ; yields {ty}:result
+ <result> = inttoptr <ty> <value> to <ty2> ; yields ty2
Overview:
-The '
mul' instruction returns the product of its two operands.
+
The 'inttoptr' instruction converts an integer value to
+a pointer type, ty2.
Arguments:
-The two arguments to the '
mul' instruction must be either
integer or
floating point values. Both arguments must have identical types.
+
The 'inttoptr' instruction takes an integer
+value to cast, and a type to cast it to, which must be a
+pointer type.
Semantics:
+
The 'inttoptr' instruction converts value to type
+ty2 by applying either a zero extension or a truncation depending on
+the size of the integer value. If value is larger than the
+size of a pointer then a truncation is done. If value is smaller than
+the size of a pointer then a zero extension is done. If they are the same size,
+nothing is done (no-op cast).
+
+
Example:
+
+ %X = inttoptr i32 255 to i32* ; yields zero extend on 64-bit
+ %X = inttoptr i32 255 to i32* ; yields no-op on 32-bit
+ %Y = inttoptr i16 0 to i32* ; yields zero extend on 32-bit
+
+
+
+
+
+
+
+
Syntax:
+
+ <result> = bitcast <ty> <value> to <ty2> ; yields ty2
+
-The value produced is the integer or floating point product of the two
-operands.
+
Overview:
+
The 'bitcast' instruction converts value to type
+ty2 without changing any bits.
-There is no signed vs unsigned multiplication. The appropriate action is taken
-based on the type of the operand.
+
Arguments:
+
The 'bitcast' instruction takes a value to cast, which must be
+a first class value, and a type to cast it to, which must also be a first class type. The bit sizes of value
+and the destination type, ty2, must be identical. If the source
+type is a pointer, the destination type must also be a pointer.
+
Semantics:
+
The 'bitcast' instruction converts value to type
+ty2. It is always a no-op cast because no bits change with
+this conversion. The conversion is done as if the value had been
+stored to memory and read back as type ty2. Pointer types may only be
+converted to other pointer types with this instruction. To convert pointers to
+other types, use the inttoptr or
+ptrtoint instructions first.
Example:
- <result> = mul int 4, %var ; yields {int}:result = 4 * %var
+ %X = bitcast i8 255 to i8 ; yields i8 :-1
+ %Y = bitcast i32* %x to sint* ; yields sint*:%x
+ %Z = bitcast <2xint> %V to i64; ; yields i64: %V
+
+
+
+
+
+
+
The instructions in this category are the "miscellaneous"
+instructions, which defy better classification.
+
+
+
+
+
+
Syntax:
+
<result> = icmp <cond> <ty> <var1>, <var2>
+; yields {i1}:result
+
+
Overview:
+
The 'icmp' instruction returns a boolean value based on comparison
+of its two integer operands.
+
Arguments:
+
The 'icmp' instruction takes three operands. The first operand is
+the condition code which indicates the kind of comparison to perform. It is not
+a value, just a keyword. The possibilities for the condition code are:
+
+ - eq: equal
+ - ne: not equal
+ - ugt: unsigned greater than
+ - uge: unsigned greater or equal
+ - ult: unsigned less than
+ - ule: unsigned less or equal
+ - sgt: signed greater than
+ - sge: signed greater or equal
+ - slt: signed less than
+ - sle: signed less or equal
+
+
The remaining two arguments must be integer or
+pointer typed. They must also be identical types.
+
Semantics:
+
The 'icmp' compares var1 and var2 according to
+the condition code given as cond. The comparison performed always
+yields a i1 result, as follows:
+
+ - eq: yields true if the operands are equal,
+ false otherwise. No sign interpretation is necessary or performed.
+
+ - ne: yields true if the operands are unequal,
+ false otherwise. No sign interpretation is necessary or performed.
+
- ugt: interprets the operands as unsigned values and yields
+ true if var1 is greater than var2.
+ - uge: interprets the operands as unsigned values and yields
+ true if var1 is greater than or equal to var2.
+ - ult: interprets the operands as unsigned values and yields
+ true if var1 is less than var2.
+ - ule: interprets the operands as unsigned values and yields
+ true if var1 is less than or equal to var2.
+ - sgt: interprets the operands as signed values and yields
+ true if var1 is greater than var2.
+ - sge: interprets the operands as signed values and yields
+ true if var1 is greater than or equal to var2.
+ - slt: interprets the operands as signed values and yields
+ true if var1 is less than var2.
+ - sle: interprets the operands as signed values and yields
+ true if var1 is less than or equal to var2.
+
+
If the operands are pointer typed, the pointer
+values are treated as integers and then compared.
+
+
Example:
+
<result> = icmp eq i32 4, 5 ; yields: result=false
+ <result> = icmp ne float* %X, %X ; yields: result=false
+ <result> = icmp ult i16 4, 5 ; yields: result=true
+ <result> = icmp sgt i16 4, 5 ; yields: result=false
+ <result> = icmp ule i16 -4, 5 ; yields: result=false
+ <result> = icmp sge i16 4, 5 ; yields: result=false
+
+
+
+
+
+
+
Syntax:
+
<result> = fcmp <cond> <ty> <var1>, <var2>
+; yields {i1}:result
+
+
Overview:
+
The 'fcmp' instruction returns a boolean value based on comparison
+of its floating point operands.
+
Arguments:
+
The 'fcmp' instruction takes three operands. The first operand is
+the condition code which indicates the kind of comparison to perform. It is not
+a value, just a keyword. The possibilities for the condition code are:
+
+ - false: no comparison, always returns false
+ - oeq: ordered and equal
+ - ogt: ordered and greater than
+ - oge: ordered and greater than or equal
+ - olt: ordered and less than
+ - ole: ordered and less than or equal
+ - one: ordered and not equal
+ - ord: ordered (no nans)
+ - ueq: unordered or equal
+ - ugt: unordered or greater than
+ - uge: unordered or greater than or equal
+ - ult: unordered or less than
+ - ule: unordered or less than or equal
+ - une: unordered or not equal
+ - uno: unordered (either nans)
+ - true: no comparison, always returns true
+
+
In the preceding, ordered means that neither operand is a QNAN while
+unordered means that either operand may be a QNAN.
+
The val1 and val2 arguments must be
+floating point typed. They must have identical
+types.
+
In the foregoing, ordered means that neither operand is a QNAN and
+unordered means that either operand is a QNAN.
+
Semantics:
+
The 'fcmp' compares var1 and var2 according to
+the condition code given as cond. The comparison performed always
+yields a i1 result, as follows:
+
+ - false: always yields false, regardless of operands.
+ - oeq: yields true if both operands are not a QNAN and
+ var1 is equal to var2.
+ - ogt: yields true if both operands are not a QNAN and
+ var1 is greather than var2.
+ - oge: yields true if both operands are not a QNAN and
+ var1 is greater than or equal to var2.
+ - olt: yields true if both operands are not a QNAN and
+ var1 is less than var2.
+ - ole: yields true if both operands are not a QNAN and
+ var1 is less than or equal to var2.
+ - one: yields true if both operands are not a QNAN and
+ var1 is not equal to var2.
+ - ord: yields true if both operands are not a QNAN.
+ - ueq: yields true if either operand is a QNAN or
+ var1 is equal to var2.
+ - ugt: yields true if either operand is a QNAN or
+ var1 is greater than var2.
+ - uge: yields true if either operand is a QNAN or
+ var1 is greater than or equal to var2.
+ - ult: yields true if either operand is a QNAN or
+ var1 is less than var2.
+ - ule: yields true if either operand is a QNAN or
+ var1 is less than or equal to var2.
+ - une: yields true if either operand is a QNAN or
+ var1 is not equal to var2.
+ - uno: yields true if either operand is a QNAN.
+ - true: always yields true, regardless of operands.
+
+
+
Example:
+
<result> = fcmp oeq float 4.0, 5.0 ; yields: result=false
+ <result> = icmp one float 4.0, 5.0 ; yields: result=true
+ <result> = icmp olt float 4.0, 5.0 ; yields: result=true
+ <result> = icmp ueq double 1.0, 2.0 ; yields: result=false
+
+
+
+
+
Syntax:
+
<result> = phi <ty> [ <val0>, <label0>], ...
+
Overview:
+
The 'phi' instruction is used to implement the φ node in
+the SSA graph representing the function.
+
Arguments:
+
The type of the incoming values are specified with the first type
+field. After this, the 'phi' instruction takes a list of pairs
+as arguments, with one pair for each predecessor basic block of the
+current block. Only values of first class
+type may be used as the value arguments to the PHI node. Only labels
+may be used as the label arguments.
+
There must be no non-phi instructions between the start of a basic
+block and the PHI instructions: i.e. PHI instructions must be first in
+a basic block.
+
Semantics:
+
At runtime, the 'phi' instruction logically takes on the
+value specified by the parameter, depending on which basic block we
+came from in the last terminator instruction.
+
Example:
+
Loop: ; Infinite loop that counts from 0 on up...
%indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
%nextindvar = add i32 %indvar, 1
br label %Loop
+
-