MLIR

Multi-Level IR Compiler Framework

'arith' Dialect

The arith dialect is intended to hold basic integer and floating point mathematical operations. This includes unary, binary, and ternary arithmetic ops, bitwise and shift ops, cast ops, and compare ops. Operations in this dialect also accept vectors and tensors of integers or floats. The dialect assumes integers are represented by bitvectors with a two’s complement representation. Unless otherwise stated, the operations within this dialect propagate poison values, i.e., if any of its inputs are poison, then the output is poison. Unless otherwise stated, operations applied to vector and tensor values propagates poison elementwise.

Operations 

source

arith.addf (arith::AddFOp) 

Floating point addition operation

Syntax:

operation ::= `arith.addf` $lhs `,` $rhs (`fastmath` `` $fastmath^)?
              attr-dict `:` type($result)

The addf operation takes two operands and returns one result, each of these is required to be the same type. This type may be a floating point scalar type, a vector whose element type is a floating point type, or a floating point tensor.

Example:

// Scalar addition.
%a = arith.addf %b, %c : f64

// SIMD vector addition, e.g. for Intel SSE.
%f = arith.addf %g, %h : vector<4xf32>

// Tensor addition.
%x = arith.addf %y, %z : tensor<4x?xbf16>

TODO: In the distant future, this will accept optional attributes for fast math, contraction, rounding mode, and other controls.

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

arith.addi (arith::AddIOp) 

Integer addition operation

Syntax:

operation ::= `arith.addi` $lhs `,` $rhs (`overflow` `` $overflowFlags^)?
              attr-dict `:` type($result)

Performs N-bit addition on the operands. The operands are interpreted as unsigned bitvectors. The result is represented by a bitvector containing the mathematical value of the addition modulo 2^n, where n is the bitwidth. Because arith integers use a two’s complement representation, this operation is applicable on both signed and unsigned integer operands.

The addi operation takes two operands and returns one result, each of these is required to be the same type. This type may be an integer scalar type, a vector whose element type is integer, or a tensor of integers.

This op supports nuw/nsw overflow flags which stands stand for “No Unsigned Wrap” and “No Signed Wrap”, respectively. If the nuw and/or nsw flags are present, and an unsigned/signed overflow occurs (respectively), the result is poison.

Example:

// Scalar addition.
%a = arith.addi %b, %c : i64

// Scalar addition with overflow flags.
%a = arith.addi %b, %c overflow<nsw, nuw> : i64

// SIMD vector element-wise addition.
%f = arith.addi %g, %h : vector<4xi32>

// Tensor element-wise addition.
%x = arith.addi %y, %z : tensor<4x?xi8>

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithIntegerOverflowFlagsInterface, ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
overflowFlags::mlir::arith::IntegerOverflowFlagsAttr
Integer overflow arith flags

Enum cases:

  • none (none)
  • nsw (nsw)
  • nuw (nuw)

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.addui_extended (arith::AddUIExtendedOp) 

Extended unsigned integer addition operation returning sum and overflow bit

Syntax:

operation ::= `arith.addui_extended` $lhs `,` $rhs attr-dict `:` type($sum) `,` type($overflow)

Performs (N+1)-bit addition on zero-extended operands. Returns two results: the N-bit sum (same type as both operands), and the overflow bit (boolean-like), where 1 indicates unsigned addition overflow, while 0 indicates no overflow.

Example:

// Scalar addition.
%sum, %overflow = arith.addui_extended %b, %c : i64, i1

// Vector element-wise addition.
%d:2 = arith.addui_extended %e, %f : vector<4xi32>, vector<4xi1>

// Tensor element-wise addition.
%x:2 = arith.addui_extended %y, %z : tensor<4x?xi8>, tensor<4x?xi1>

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
sumsignless-integer-like
overflowbool-like

arith.andi (arith::AndIOp) 

Integer binary and

Syntax:

operation ::= `arith.andi` $lhs `,` $rhs attr-dict `:` type($result)

The andi operation takes two operands and returns one result, each of these is required to be the same type. This type may be an integer scalar type, a vector whose element type is integer, or a tensor of integers. It has no standard attributes.

Example:

// Scalar integer bitwise and.
%a = arith.andi %b, %c : i64

// SIMD vector element-wise bitwise integer and.
%f = arith.andi %g, %h : vector<4xi32>

// Tensor element-wise bitwise integer and.
%x = arith.andi %y, %z : tensor<4x?xi8>

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, Idempotent, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.bitcast (arith::BitcastOp) 

Bitcast between values of equal bit width

Syntax:

operation ::= `arith.bitcast` $in attr-dict `:` type($in) `to` type($out)

Bitcast an integer or floating point value to an integer or floating point value of equal bit width. When operating on vectors, casts elementwise.

Note that this implements a logical bitcast independent of target endianness. This allows constant folding without target information and is consitent with the bitcast constant folders in LLVM (see https://github.com/llvm/llvm-project/blob/18c19414eb/llvm/lib/IR/ConstantFold.cpp#L168) For targets where the source and target type have the same endianness (which is the standard), this cast will also change no bits at runtime, but it may still require an operation, for example if the machine has different floating point and integer register files. For targets that have a different endianness for the source and target types (e.g. float is big-endian and integer is little-endian) a proper lowering would add operations to swap the order of words in addition to the bitcast.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: CastOpInterface, ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
insignless-integer-or-float-like or memref of signless-integer or float

Results: 

ResultDescription
outsignless-integer-or-float-like or memref of signless-integer or float

arith.ceildivsi (arith::CeilDivSIOp) 

Signed ceil integer division operation

Syntax:

operation ::= `arith.ceildivsi` $lhs `,` $rhs attr-dict `:` type($result)

Signed integer division. Rounds towards positive infinity, i.e. 7 / -2 = -3.

Divison by zero, or signed division overflow (minimum value divided by -1) is undefined behavior. When applied to vector and tensor values, the behavior is undefined if any of its elements are divided by zero or has a signed division overflow.

Example:

// Scalar signed integer division.
%a = arith.ceildivsi %b, %c : i64

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.ceildivui (arith::CeilDivUIOp) 

Unsigned ceil integer division operation

Syntax:

operation ::= `arith.ceildivui` $lhs `,` $rhs attr-dict `:` type($result)

Unsigned integer division. Rounds towards positive infinity. Treats the leading bit as the most significant, i.e. for i16 given two’s complement representation, 6 / -2 = 6 / (2^16 - 2) = 1.

Division by zero is undefined behavior. When applied to vector and tensor values, the behavior is undefined if any elements are divided by zero.

Example:

// Scalar unsigned integer division.
%a = arith.ceildivui %b, %c : i64

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.cmpf (arith::CmpFOp) 

Floating-point comparison operation

Syntax:

operation ::= `arith.cmpf` $predicate `,` $lhs `,` $rhs (`fastmath` `` $fastmath^)?
              attr-dict `:` type($lhs)

The cmpf operation compares its two operands according to the float comparison rules and the predicate specified by the respective attribute. The predicate defines the type of comparison: (un)orderedness, (in)equality and signed less/greater than (or equal to) as well as predicates that are always true or false. The operands must have the same type, and this type must be a float type, or a vector or tensor thereof. The result is an i1, or a vector/tensor thereof having the same shape as the inputs. Unlike cmpi, the operands are always treated as signed. The u prefix indicates unordered comparison, not unsigned comparison, so “une” means unordered or not equal. For the sake of readability by humans, custom assembly form for the operation uses a string-typed attribute for the predicate. The value of this attribute corresponds to lower-cased name of the predicate constant, e.g., “one” means “ordered not equal”. The string representation of the attribute is merely a syntactic sugar and is converted to an integer attribute by the parser.

Example:

%r1 = arith.cmpf oeq, %0, %1 : f32
%r2 = arith.cmpf ult, %0, %1 : tensor<42x42xf64>
%r3 = "arith.cmpf"(%0, %1) {predicate: 0} : (f8, f8) -> i1

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameTypeOperands, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
predicate::mlir::arith::CmpFPredicateAttr
allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15

Enum cases:

  • false (AlwaysFalse)
  • oeq (OEQ)
  • ogt (OGT)
  • oge (OGE)
  • olt (OLT)
  • ole (OLE)
  • one (ONE)
  • ord (ORD)
  • ueq (UEQ)
  • ugt (UGT)
  • uge (UGE)
  • ult (ULT)
  • ule (ULE)
  • une (UNE)
  • uno (UNO)
  • true (AlwaysTrue)
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultbool-like

arith.cmpi (arith::CmpIOp) 

Integer comparison operation

Syntax:

operation ::= `arith.cmpi` $predicate `,` $lhs `,` $rhs attr-dict `:` type($lhs)

The cmpi operation is a generic comparison for integer-like types. Its two arguments can be integers, vectors or tensors thereof as long as their types match. The operation produces an i1 for the former case, a vector or a tensor of i1 with the same shape as inputs in the other cases.

Its first argument is an attribute that defines which type of comparison is performed. The following comparisons are supported:

  • equal (mnemonic: "eq"; integer value: 0)
  • not equal (mnemonic: "ne"; integer value: 1)
  • signed less than (mnemonic: "slt"; integer value: 2)
  • signed less than or equal (mnemonic: "sle"; integer value: 3)
  • signed greater than (mnemonic: "sgt"; integer value: 4)
  • signed greater than or equal (mnemonic: "sge"; integer value: 5)
  • unsigned less than (mnemonic: "ult"; integer value: 6)
  • unsigned less than or equal (mnemonic: "ule"; integer value: 7)
  • unsigned greater than (mnemonic: "ugt"; integer value: 8)
  • unsigned greater than or equal (mnemonic: "uge"; integer value: 9)

The result is 1 if the comparison is true and 0 otherwise. For vector or tensor operands, the comparison is performed elementwise and the element of the result indicates whether the comparison is true for the operand elements with the same indices as those of the result.

Note: while the custom assembly form uses strings, the actual underlying attribute has integer type (or rather enum class in C++ code) as seen from the generic assembly form. String literals are used to improve readability of the IR by humans.

This operation only applies to integer-like operands, but not floats. The main reason being that comparison operations have diverging sets of attributes: integers require sign specification while floats require various floating point-related particularities, e.g., -ffast-math behavior, IEEE754 compliance, etc ( rationale). The type of comparison is specified as attribute to avoid introducing ten similar operations, taking into account that they are often implemented using the same operation downstream ( rationale). The separation between signed and unsigned order comparisons is necessary because of integers being signless. The comparison operation must know how to interpret values with the foremost bit being set: negatives in two’s complement or large positives ( rationale).

Example:

// Custom form of scalar "signed less than" comparison.
%x = arith.cmpi slt, %lhs, %rhs : i32

// Generic form of the same operation.
%x = "arith.cmpi"(%lhs, %rhs) {predicate = 2 : i64} : (i32, i32) -> i1

// Custom form of vector equality comparison.
%x = arith.cmpi eq, %lhs, %rhs : vector<4xi64>

// Generic form of the same operation.
%x = "arith.cmpi"(%lhs, %rhs) {predicate = 0 : i64}
    : (vector<4xi64>, vector<4xi64>) -> vector<4xi1>

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameTypeOperands, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
predicate::mlir::arith::CmpIPredicateAttr
allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Enum cases:

  • eq (eq)
  • ne (ne)
  • slt (slt)
  • sle (sle)
  • sgt (sgt)
  • sge (sge)
  • ult (ult)
  • ule (ule)
  • ugt (ugt)
  • uge (uge)

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultbool-like

arith.constant (arith::ConstantOp) 

Integer or floating point constant

Syntax:

operation ::= `arith.constant` attr-dict $value

The constant operation produces an SSA value equal to some integer or floating-point constant specified by an attribute. This is the way MLIR forms simple integer and floating point constants.

Example:

// Integer constant
%1 = arith.constant 42 : i32

// Equivalent generic form
%1 = "arith.constant"() {value = 42 : i32} : () -> i32

Traits: AlwaysSpeculatableImplTrait, ConstantLike

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), OpAsmOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
value::mlir::TypedAttr
TypedAttr instance
This interface is used for attributes that have a type. The type of an
attribute is understood to represent the type of the data contained in the
attribute and is often used as the type of a value with this data.

Results: 

ResultDescription
resultany type

arith.divf (arith::DivFOp) 

Floating point division operation

Syntax:

operation ::= `arith.divf` $lhs `,` $rhs (`fastmath` `` $fastmath^)?
              attr-dict `:` type($result)

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

arith.divsi (arith::DivSIOp) 

Signed integer division operation

Syntax:

operation ::= `arith.divsi` $lhs `,` $rhs attr-dict `:` type($result)

Signed integer division. Rounds towards zero. Treats the leading bit as sign, i.e. 6 / -2 = -3.

Divison by zero, or signed division overflow (minimum value divided by -1) is undefined behavior. When applied to vector and tensor values, the behavior is undefined if any of its elements are divided by zero or has a signed division overflow.

Example:

// Scalar signed integer division.
%a = arith.divsi %b, %c : i64

// SIMD vector element-wise division.
%f = arith.divsi %g, %h : vector<4xi32>

// Tensor element-wise integer division.
%x = arith.divsi %y, %z : tensor<4x?xi8>

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.divui (arith::DivUIOp) 

Unsigned integer division operation

Syntax:

operation ::= `arith.divui` $lhs `,` $rhs attr-dict `:` type($result)

Unsigned integer division. Rounds towards zero. Treats the leading bit as the most significant, i.e. for i16 given two’s complement representation, 6 / -2 = 6 / (2^16 - 2) = 0.

Division by zero is undefined behavior. When applied to vector and tensor values, the behavior is undefined if any elements are divided by zero.

Example:

// Scalar unsigned integer division.
%a = arith.divui %b, %c : i64

// SIMD vector element-wise division.
%f = arith.divui %g, %h : vector<4xi32>

// Tensor element-wise integer division.
%x = arith.divui %y, %z : tensor<4x?xi8>

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.extf (arith::ExtFOp) 

Cast from floating-point to wider floating-point

Syntax:

operation ::= `arith.extf` $in (`fastmath` `` $fastmath^)?
              attr-dict `:` type($in) `to` type($out)

Cast a floating-point value to a larger floating-point-typed value. The destination type must to be strictly wider than the source type. When operating on vectors, casts elementwise.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, CastOpInterface, ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
infloating-point-like

Results: 

ResultDescription
outfloating-point-like

arith.extsi (arith::ExtSIOp) 

Integer sign extension operation

Syntax:

operation ::= `arith.extsi` $in attr-dict `:` type($in) `to` type($out)

The integer sign extension operation takes an integer input of width M and an integer destination type of width N. The destination bit-width must be larger than the input bit-width (N > M). The top-most (N - M) bits of the output are filled with copies of the most-significant bit of the input.

Example:

%1 = arith.constant 5 : i3      // %1 is 0b101
%2 = arith.extsi %1 : i3 to i6  // %2 is 0b111101
%3 = arith.constant 2 : i3      // %3 is 0b010
%4 = arith.extsi %3 : i3 to i6  // %4 is 0b000010

%5 = arith.extsi %0 : vector<2 x i32> to vector<2 x i64>

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: CastOpInterface, ConditionallySpeculatable, InferIntRangeInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
insignless-fixed-width-integer-like

Results: 

ResultDescription
outsignless-fixed-width-integer-like

arith.extui (arith::ExtUIOp) 

Integer zero extension operation

Syntax:

operation ::= `arith.extui` $in attr-dict `:` type($in) `to` type($out)

The integer zero extension operation takes an integer input of width M and an integer destination type of width N. The destination bit-width must be larger than the input bit-width (N > M). The top-most (N - M) bits of the output are filled with zeros.

Example:

  %1 = arith.constant 5 : i3      // %1 is 0b101
  %2 = arith.extui %1 : i3 to i6  // %2 is 0b000101
  %3 = arith.constant 2 : i3      // %3 is 0b010
  %4 = arith.extui %3 : i3 to i6  // %4 is 0b000010

  %5 = arith.extui %0 : vector<2 x i32> to vector<2 x i64>

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: CastOpInterface, ConditionallySpeculatable, InferIntRangeInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
insignless-fixed-width-integer-like

Results: 

ResultDescription
outsignless-fixed-width-integer-like

arith.floordivsi (arith::FloorDivSIOp) 

Signed floor integer division operation

Syntax:

operation ::= `arith.floordivsi` $lhs `,` $rhs attr-dict `:` type($result)

Signed integer division. Rounds towards negative infinity, i.e. 5 / -2 = -3.

Divison by zero, or signed division overflow (minimum value divided by -1) is undefined behavior. When applied to vector and tensor values, the behavior is undefined if any of its elements are divided by zero or has a signed division overflow.

Example:

// Scalar signed integer division.
%a = arith.floordivsi %b, %c : i64

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.fptosi (arith::FPToSIOp) 

Cast from floating-point type to integer type

Syntax:

operation ::= `arith.fptosi` $in attr-dict `:` type($in) `to` type($out)

Cast from a value interpreted as floating-point to the nearest (rounding towards zero) signed integer value. When operating on vectors, casts elementwise.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: CastOpInterface, ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
infloating-point-like

Results: 

ResultDescription
outsignless-fixed-width-integer-like

arith.fptoui (arith::FPToUIOp) 

Cast from floating-point type to integer type

Syntax:

operation ::= `arith.fptoui` $in attr-dict `:` type($in) `to` type($out)

Cast from a value interpreted as floating-point to the nearest (rounding towards zero) unsigned integer value. When operating on vectors, casts elementwise.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: CastOpInterface, ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
infloating-point-like

Results: 

ResultDescription
outsignless-fixed-width-integer-like

arith.index_cast (arith::IndexCastOp) 

Cast between index and integer types

Syntax:

operation ::= `arith.index_cast` $in attr-dict `:` type($in) `to` type($out)

Casts between scalar or vector integers and corresponding ‘index’ scalar or vectors. Index is an integer of platform-specific bit width. If casting to a wider integer, the value is sign-extended. If casting to a narrower integer, the value is truncated.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: CastOpInterface, ConditionallySpeculatable, InferIntRangeInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
insignless-integer-like or memref of signless-integer

Results: 

ResultDescription
outsignless-integer-like or memref of signless-integer

arith.index_castui (arith::IndexCastUIOp) 

Unsigned cast between index and integer types

Syntax:

operation ::= `arith.index_castui` $in attr-dict `:` type($in) `to` type($out)

Casts between scalar or vector integers and corresponding ‘index’ scalar or vectors. Index is an integer of platform-specific bit width. If casting to a wider integer, the value is zero-extended. If casting to a narrower integer, the value is truncated.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: CastOpInterface, ConditionallySpeculatable, InferIntRangeInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
insignless-integer-like or memref of signless-integer

Results: 

ResultDescription
outsignless-integer-like or memref of signless-integer

arith.maximumf (arith::MaximumFOp) 

Floating-point maximum operation

Syntax:

operation ::= `arith.maximumf` $lhs `,` $rhs (`fastmath` `` $fastmath^)?
              attr-dict `:` type($result)

Returns the maximum of the two arguments, treating -0.0 as less than +0.0. If one of the arguments is NaN, then the result is also NaN.

Example:

// Scalar floating-point maximum.
%a = arith.maximumf %b, %c : f64

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

arith.maxnumf (arith::MaxNumFOp) 

Floating-point maximum operation

Syntax:

operation ::= `arith.maxnumf` $lhs `,` $rhs (`fastmath` `` $fastmath^)?
              attr-dict `:` type($result)

Returns the maximum of the two arguments. If the arguments are -0.0 and +0.0, then the result is either of them. If one of the arguments is NaN, then the result is the other argument.

Example:

// Scalar floating-point maximum.
%a = arith.maxnumf %b, %c : f64

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

arith.maxsi (arith::MaxSIOp) 

Signed integer maximum operation

Syntax:

operation ::= `arith.maxsi` $lhs `,` $rhs attr-dict `:` type($result)

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.maxui (arith::MaxUIOp) 

Unsigned integer maximum operation

Syntax:

operation ::= `arith.maxui` $lhs `,` $rhs attr-dict `:` type($result)

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.minimumf (arith::MinimumFOp) 

Floating-point minimum operation

Syntax:

operation ::= `arith.minimumf` $lhs `,` $rhs (`fastmath` `` $fastmath^)?
              attr-dict `:` type($result)

Returns the minimum of the two arguments, treating -0.0 as less than +0.0. If one of the arguments is NaN, then the result is also NaN.

Example:

// Scalar floating-point minimum.
%a = arith.minimumf %b, %c : f64

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

arith.minnumf (arith::MinNumFOp) 

Floating-point minimum operation

Syntax:

operation ::= `arith.minnumf` $lhs `,` $rhs (`fastmath` `` $fastmath^)?
              attr-dict `:` type($result)

Returns the minimum of the two arguments. If the arguments are -0.0 and +0.0, then the result is either of them. If one of the arguments is NaN, then the result is the other argument.

Example:

// Scalar floating-point minimum.
%a = arith.minnumf %b, %c : f64

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

arith.minsi (arith::MinSIOp) 

Signed integer minimum operation

Syntax:

operation ::= `arith.minsi` $lhs `,` $rhs attr-dict `:` type($result)

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.minui (arith::MinUIOp) 

Unsigned integer minimum operation

Syntax:

operation ::= `arith.minui` $lhs `,` $rhs attr-dict `:` type($result)

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.mulf (arith::MulFOp) 

Floating point multiplication operation

Syntax:

operation ::= `arith.mulf` $lhs `,` $rhs (`fastmath` `` $fastmath^)?
              attr-dict `:` type($result)

The mulf operation takes two operands and returns one result, each of these is required to be the same type. This type may be a floating point scalar type, a vector whose element type is a floating point type, or a floating point tensor.

Example:

// Scalar multiplication.
%a = arith.mulf %b, %c : f64

// SIMD pointwise vector multiplication, e.g. for Intel SSE.
%f = arith.mulf %g, %h : vector<4xf32>

// Tensor pointwise multiplication.
%x = arith.mulf %y, %z : tensor<4x?xbf16>

TODO: In the distant future, this will accept optional attributes for fast math, contraction, rounding mode, and other controls.

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

arith.muli (arith::MulIOp) 

Integer multiplication operation.

Syntax:

operation ::= `arith.muli` $lhs `,` $rhs (`overflow` `` $overflowFlags^)?
              attr-dict `:` type($result)

Performs N-bit multiplication on the operands. The operands are interpreted as unsigned bitvectors. The result is represented by a bitvector containing the mathematical value of the multiplication modulo 2^n, where n is the bitwidth. Because arith integers use a two’s complement representation, this operation is applicable on both signed and unsigned integer operands.

The muli operation takes two operands and returns one result, each of these is required to be the same type. This type may be an integer scalar type, a vector whose element type is integer, or a tensor of integers.

This op supports nuw/nsw overflow flags which stands stand for “No Unsigned Wrap” and “No Signed Wrap”, respectively. If the nuw and/or nsw flags are present, and an unsigned/signed overflow occurs (respectively), the result is poison.

Example:

// Scalar multiplication.
%a = arith.muli %b, %c : i64

// Scalar multiplication with overflow flags.
%a = arith.muli %b, %c overflow<nsw, nuw> : i64

// SIMD vector element-wise multiplication.
%f = arith.muli %g, %h : vector<4xi32>

// Tensor element-wise multiplication.
%x = arith.muli %y, %z : tensor<4x?xi8>

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithIntegerOverflowFlagsInterface, ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), OpAsmOpInterface, VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
overflowFlags::mlir::arith::IntegerOverflowFlagsAttr
Integer overflow arith flags

Enum cases:

  • none (none)
  • nsw (nsw)
  • nuw (nuw)

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.mulsi_extended (arith::MulSIExtendedOp) 

Extended signed integer multiplication operation

Syntax:

operation ::= `arith.mulsi_extended` $lhs `,` $rhs attr-dict `:` type($lhs)

Performs (2*N)-bit multiplication on sign-extended operands. Returns two N-bit results: the low and the high halves of the product. The low half has the same value as the result of regular multiplication arith.muli with the same operands.

Example:

// Scalar multiplication.
%low, %high = arith.mulsi_extended %a, %b : i32

// Vector element-wise multiplication.
%c:2 = arith.mulsi_extended %d, %e : vector<4xi32>

// Tensor element-wise multiplication.
%x:2 = arith.mulsi_extended %y, %z : tensor<4x?xi8>

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
lowsignless-integer-like
highsignless-integer-like

arith.mului_extended (arith::MulUIExtendedOp) 

Extended unsigned integer multiplication operation

Syntax:

operation ::= `arith.mului_extended` $lhs `,` $rhs attr-dict `:` type($lhs)

Performs (2*N)-bit multiplication on zero-extended operands. Returns two N-bit results: the low and the high halves of the product. The low half has the same value as the result of regular multiplication arith.muli with the same operands.

Example:

// Scalar multiplication.
%low, %high = arith.mului_extended %a, %b : i32

// Vector element-wise multiplication.
%c:2 = arith.mului_extended %d, %e : vector<4xi32>

// Tensor element-wise multiplication.
%x:2 = arith.mului_extended %y, %z : tensor<4x?xi8>

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
lowsignless-integer-like
highsignless-integer-like

arith.negf (arith::NegFOp) 

Floating point negation

Syntax:

operation ::= `arith.negf` $operand (`fastmath` `` $fastmath^)?
              attr-dict `:` type($result)

The negf operation computes the negation of a given value. It takes one operand and returns one result of the same type. This type may be a float scalar type, a vector whose element type is float, or a tensor of floats. It has no standard attributes.

Example:

// Scalar negation value.
%a = arith.negf %b : f64

// SIMD vector element-wise negation value.
%f = arith.negf %g : vector<4xf32>

// Tensor element-wise negation value.
%x = arith.negf %y : tensor<4x?xf8>

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

arith.ori (arith::OrIOp) 

Integer binary or

Syntax:

operation ::= `arith.ori` $lhs `,` $rhs attr-dict `:` type($result)

The ori operation takes two operands and returns one result, each of these is required to be the same type. This type may be an integer scalar type, a vector whose element type is integer, or a tensor of integers. It has no standard attributes.

Example:

// Scalar integer bitwise or.
%a = arith.ori %b, %c : i64

// SIMD vector element-wise bitwise integer or.
%f = arith.ori %g, %h : vector<4xi32>

// Tensor element-wise bitwise integer or.
%x = arith.ori %y, %z : tensor<4x?xi8>

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, Idempotent, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.remf (arith::RemFOp) 

Floating point division remainder operation

Syntax:

operation ::= `arith.remf` $lhs `,` $rhs (`fastmath` `` $fastmath^)?
              attr-dict `:` type($result)

Returns the floating point division remainder. The remainder has the same sign as the dividend (lhs operand).

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

arith.remsi (arith::RemSIOp) 

Signed integer division remainder operation

Syntax:

operation ::= `arith.remsi` $lhs `,` $rhs attr-dict `:` type($result)

Signed integer division remainder. Treats the leading bit as sign, i.e. 6 % -2 = 0.

Division by zero is undefined behavior. When applied to vector and tensor values, the behavior is undefined if any elements are divided by zero.

Example:

// Scalar signed integer division remainder.
%a = arith.remsi %b, %c : i64

// SIMD vector element-wise division remainder.
%f = arith.remsi %g, %h : vector<4xi32>

// Tensor element-wise integer division remainder.
%x = arith.remsi %y, %z : tensor<4x?xi8>

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.remui (arith::RemUIOp) 

Unsigned integer division remainder operation

Syntax:

operation ::= `arith.remui` $lhs `,` $rhs attr-dict `:` type($result)

Unsigned integer division remainder. Treats the leading bit as the most significant, i.e. for i16, 6 % -2 = 6 % (2^16 - 2) = 6.

Division by zero is undefined behavior. When applied to vector and tensor values, the behavior is undefined if any elements are divided by zero.

Example:

// Scalar unsigned integer division remainder.
%a = arith.remui %b, %c : i64

// SIMD vector element-wise division remainder.
%f = arith.remui %g, %h : vector<4xi32>

// Tensor element-wise integer division remainder.
%x = arith.remui %y, %z : tensor<4x?xi8>

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.select (arith::SelectOp) 

Select operation

The arith.select operation chooses one value based on a binary condition supplied as its first operand.

If the value of the first operand (the condition) is 1, then the second operand is returned, and the third operand is ignored, even if it was poison.

If the value of the first operand (the condition) is 0, then the third operand is returned, and the second operand is ignored, even if it was poison.

If the value of the first operand (the condition) is poison, then the operation returns poison.

The operation applies to vectors and tensors elementwise given the shape of all operands is identical. The choice is made for each element individually based on the value at the same position as the element in the condition operand. If an i1 is provided as the condition, the entire vector or tensor is chosen.

Example:

// Custom form of scalar selection.
%x = arith.select %cond, %true, %false : i32

// Generic form of the same operation.
%x = "arith.select"(%cond, %true, %false) : (i1, i32, i32) -> i32

// Element-wise vector selection.
%vx = arith.select %vcond, %vtrue, %vfalse : vector<42xi1>, vector<42xf32>

// Full vector selection.
%vx = arith.select %cond, %vtrue, %vfalse : vector<42xf32>

Traits: AlwaysSpeculatableImplTrait, Elementwise, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), SelectLikeOpInterface, VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
conditionbool-like
true_valueany type
false_valueany type

Results: 

ResultDescription
resultany type

arith.shli (arith::ShLIOp) 

Integer left-shift

Syntax:

operation ::= `arith.shli` $lhs `,` $rhs (`overflow` `` $overflowFlags^)?
              attr-dict `:` type($result)

The shli operation shifts the integer value of the first operand to the left by the integer value of the second operand. The second operand is interpreted as unsigned. The low order bits are filled with zeros. If the value of the second operand is greater or equal than the bitwidth of the first operand, then the operation returns poison.

This op supports nuw/nsw overflow flags which stands stand for “No Unsigned Wrap” and “No Signed Wrap”, respectively. If the nuw and/or nsw flags are present, and an unsigned/signed overflow occurs (respectively), the result is poison.

Example:

%1 = arith.constant 5 : i8  // %1 is 0b00000101
%2 = arith.constant 3 : i8
%3 = arith.shli %1, %2 : i8 // %3 is 0b00101000
%4 = arith.shli %1, %2 overflow<nsw, nuw> : i8  

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithIntegerOverflowFlagsInterface, ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
overflowFlags::mlir::arith::IntegerOverflowFlagsAttr
Integer overflow arith flags

Enum cases:

  • none (none)
  • nsw (nsw)
  • nuw (nuw)

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.shrsi (arith::ShRSIOp) 

Signed integer right-shift

Syntax:

operation ::= `arith.shrsi` $lhs `,` $rhs attr-dict `:` type($result)

The shrsi operation shifts an integer value of the first operand to the right by the value of the second operand. The first operand is interpreted as signed, and the second operand is interpreter as unsigned. The high order bits in the output are filled with copies of the most-significant bit of the shifted value (which means that the sign of the value is preserved). If the value of the second operand is greater or equal than bitwidth of the first operand, then the operation returns poison.

Example:

%1 = arith.constant 160 : i8               // %1 is 0b10100000
%2 = arith.constant 3 : i8
%3 = arith.shrsi %1, %2 : (i8, i8) -> i8   // %3 is 0b11110100
%4 = arith.constant 96 : i8                   // %4 is 0b01100000
%5 = arith.shrsi %4, %2 : (i8, i8) -> i8   // %5 is 0b00001100

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.shrui (arith::ShRUIOp) 

Unsigned integer right-shift

Syntax:

operation ::= `arith.shrui` $lhs `,` $rhs attr-dict `:` type($result)

The shrui operation shifts an integer value of the first operand to the right by the value of the second operand. The first operand is interpreted as unsigned, and the second operand is interpreted as unsigned. The high order bits are always filled with zeros. If the value of the second operand is greater or equal than the bitwidth of the first operand, then the operation returns poison.

Example:

%1 = arith.constant 160 : i8               // %1 is 0b10100000
%2 = arith.constant 3 : i8
%3 = arith.shrui %1, %2 : (i8, i8) -> i8   // %3 is 0b00010100

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.sitofp (arith::SIToFPOp) 

Cast from integer type to floating-point

Syntax:

operation ::= `arith.sitofp` $in attr-dict `:` type($in) `to` type($out)

Cast from a value interpreted as a signed integer to the corresponding floating-point value. If the value cannot be exactly represented, it is rounded using the default rounding mode. When operating on vectors, casts elementwise.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: CastOpInterface, ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
insignless-fixed-width-integer-like

Results: 

ResultDescription
outfloating-point-like

arith.subf (arith::SubFOp) 

Floating point subtraction operation

Syntax:

operation ::= `arith.subf` $lhs `,` $rhs (`fastmath` `` $fastmath^)?
              attr-dict `:` type($result)

The subf operation takes two operands and returns one result, each of these is required to be the same type. This type may be a floating point scalar type, a vector whose element type is a floating point type, or a floating point tensor.

Example:

// Scalar subtraction.
%a = arith.subf %b, %c : f64

// SIMD vector subtraction, e.g. for Intel SSE.
%f = arith.subf %g, %h : vector<4xf32>

// Tensor subtraction.
%x = arith.subf %y, %z : tensor<4x?xbf16>

TODO: In the distant future, this will accept optional attributes for fast math, contraction, rounding mode, and other controls.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

arith.subi (arith::SubIOp) 

Integer subtraction operation.

Syntax:

operation ::= `arith.subi` $lhs `,` $rhs (`overflow` `` $overflowFlags^)?
              attr-dict `:` type($result)

Performs N-bit subtraction on the operands. The operands are interpreted as unsigned bitvectors. The result is represented by a bitvector containing the mathematical value of the subtraction modulo 2^n, where n is the bitwidth. Because arith integers use a two’s complement representation, this operation is applicable on both signed and unsigned integer operands.

The subi operation takes two operands and returns one result, each of these is required to be the same type. This type may be an integer scalar type, a vector whose element type is integer, or a tensor of integers.

This op supports nuw/nsw overflow flags which stands stand for “No Unsigned Wrap” and “No Signed Wrap”, respectively. If the nuw and/or nsw flags are present, and an unsigned/signed overflow occurs (respectively), the result is poison.

Example:

// Scalar subtraction.
%a = arith.subi %b, %c : i64

// Scalar subtraction with overflow flags.
%a = arith.subi %b, %c overflow<nsw, nuw> : i64

// SIMD vector element-wise subtraction.
%f = arith.subi %g, %h : vector<4xi32>

// Tensor element-wise subtraction.
%x = arith.subi %y, %z : tensor<4x?xi8>

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithIntegerOverflowFlagsInterface, ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
overflowFlags::mlir::arith::IntegerOverflowFlagsAttr
Integer overflow arith flags

Enum cases:

  • none (none)
  • nsw (nsw)
  • nuw (nuw)

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

arith.truncf (arith::TruncFOp) 

Cast from floating-point to narrower floating-point

Syntax:

operation ::= `arith.truncf` $in ($roundingmode^)?
              (`fastmath` `` $fastmath^)?
              attr-dict `:` type($in) `to` type($out)

Truncate a floating-point value to a smaller floating-point-typed value. The destination type must be strictly narrower than the source type. If the value cannot be exactly represented, it is rounded using the provided rounding mode or the default one if no rounding mode is provided. When operating on vectors, casts elementwise.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: ArithFastMathInterface, ArithRoundingModeInterface, CastOpInterface, ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
roundingmode::mlir::arith::RoundingModeAttr
Floating point rounding mode

Enum cases:

  • to_nearest_even (to_nearest_even)
  • downward (downward)
  • upward (upward)
  • toward_zero (toward_zero)
  • to_nearest_away (to_nearest_away)
fastmath::mlir::arith::FastMathFlagsAttr
Floating point fast math flags

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Operands: 

OperandDescription
infloating-point-like

Results: 

ResultDescription
outfloating-point-like

arith.trunci (arith::TruncIOp) 

Integer truncation operation

Syntax:

operation ::= `arith.trunci` $in attr-dict `:` type($in) `to` type($out)

The integer truncation operation takes an integer input of width M and an integer destination type of width N. The destination bit-width must be smaller than the input bit-width (N < M). The top-most (N - M) bits of the input are discarded.

Example:

  %1 = arith.constant 21 : i5     // %1 is 0b10101
  %2 = arith.trunci %1 : i5 to i4 // %2 is 0b0101
  %3 = arith.trunci %1 : i5 to i3 // %3 is 0b101

  %5 = arith.trunci %0 : vector<2 x i32> to vector<2 x i16>

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: CastOpInterface, ConditionallySpeculatable, InferIntRangeInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
insignless-fixed-width-integer-like

Results: 

ResultDescription
outsignless-fixed-width-integer-like

arith.uitofp (arith::UIToFPOp) 

Cast from unsigned integer type to floating-point

Syntax:

operation ::= `arith.uitofp` $in attr-dict `:` type($in) `to` type($out)

Cast from a value interpreted as unsigned integer to the corresponding floating-point value. If the value cannot be exactly represented, it is rounded using the default rounding mode. When operating on vectors, casts elementwise.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultShape, Scalarizable, Tensorizable, Vectorizable

Interfaces: CastOpInterface, ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
insignless-fixed-width-integer-like

Results: 

ResultDescription
outfloating-point-like

arith.xori (arith::XOrIOp) 

Integer binary xor

Syntax:

operation ::= `arith.xori` $lhs `,` $rhs attr-dict `:` type($result)

The xori operation takes two operands and returns one result, each of these is required to be the same type. This type may be an integer scalar type, a vector whose element type is integer, or a tensor of integers. It has no standard attributes.

Example:

// Scalar integer bitwise xor.
%a = arith.xori %b, %c : i64

// SIMD vector element-wise bitwise integer xor.
%f = arith.xori %g, %h : vector<4xi32>

// Tensor element-wise bitwise integer xor.
%x = arith.xori %y, %z : tensor<4x?xi8>

Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferIntRangeInterface, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

Attributes 

FastMathFlagsAttr 

Floating point fast math flags

Syntax:

#arith.fastmath<
  ::mlir::arith::FastMathFlags   # value
>

Enum cases:

  • none (none)
  • reassoc (reassoc)
  • nnan (nnan)
  • ninf (ninf)
  • nsz (nsz)
  • arcp (arcp)
  • contract (contract)
  • afn (afn)
  • fast (fast)

Parameters: 

ParameterC++ typeDescription
value::mlir::arith::FastMathFlagsan enum of type FastMathFlags

IntegerOverflowFlagsAttr 

Integer overflow arith flags

Syntax:

#arith.overflow<
  ::mlir::arith::IntegerOverflowFlags   # value
>

Enum cases:

  • none (none)
  • nsw (nsw)
  • nuw (nuw)

Parameters: 

ParameterC++ typeDescription
value::mlir::arith::IntegerOverflowFlagsan enum of type IntegerOverflowFlags

Enums 

CmpFPredicate 

allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15

Cases: 

SymbolValueString
AlwaysFalse0false
OEQ1oeq
OGT2ogt
OGE3oge
OLT4olt
OLE5ole
ONE6one
ORD7ord
UEQ8ueq
UGT9ugt
UGE10uge
ULT11ult
ULE12ule
UNE13une
UNO14uno
AlwaysTrue15true

CmpIPredicate 

allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Cases: 

SymbolValueString
eq0eq
ne1ne
slt2slt
sle3sle
sgt4sgt
sge5sge
ult6ult
ule7ule
ugt8ugt
uge9uge

IntegerOverflowFlags 

Integer overflow arith flags

Cases: 

SymbolValueString
none0none
nsw1nsw
nuw2nuw

RoundingMode 

Floating point rounding mode

Cases: 

SymbolValueString
to_nearest_even0to_nearest_even
downward1downward
upward2upward
toward_zero3toward_zero
to_nearest_away4to_nearest_away

AtomicRMWKind 

allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14

Cases: 

SymbolValueString
addf0addf
addi1addi
assign2assign
maximumf3maximumf
maxs4maxs
maxu5maxu
minimumf6minimumf
mins7mins
minu8minu
mulf9mulf
muli10muli
ori11ori
andi12andi
maxnumf13maxnumf
minnumf14minnumf

FastMathFlags 

Floating point fast math flags

Cases: 

SymbolValueString
none0none
reassoc1reassoc
nnan2nnan
ninf4ninf
nsz8nsz
arcp16arcp
contract32contract
afn64afn
fast127fast