From 2f2427e5aa6c9a4780b287832ae9def8104ecced Mon Sep 17 00:00:00 2001
From: Chris Lattner
The value produced is the integer or floating point sum of the two operands.
+If an integer sum has unsigned overflow, the result returned is the +mathematical result modulo 2n, where n is the bit width of +the result.
+Because LLVM integers use a two's complement representation, this +instruction is appropriate for both signed and unsigned integers.
<result> = add i32 4, %var ; yields {i32}:result = 4 + %var@@ -2076,6 +2081,11 @@ Both arguments must have identical types.
The value produced is the integer or floating point difference of the two operands.
+If an integer difference has unsigned overflow, the result returned is the +mathematical result modulo 2n, where n is the bit width of +the result.
+Because LLVM integers use a two's complement representation, this +instruction is appropriate for both signed and unsigned integers.
<result> = sub i32 4, %var ; yields {i32}:result = 4 - %var @@ -2101,9 +2111,15 @@ 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.
+If the result of an integer multiplication has unsigned overflow, +the result returned is the mathematical result modulo +2n, where n is the bit width of the result.
+Because LLVM integers use a two's complement representation, and the +result is the same width as the operands, this instruction returns the +correct result for both signed and unsigned integers. If a full product +(e.g. i32xi32->i64) is needed, the operands +should be sign-extended or zero-extended as appropriate to the +width of the full product.
Example:
<result> = mul i32 4, %var ; yields {i32}:result = 4 * %var@@ -2124,9 +2140,10 @@ operands. 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.
+The value produced is the unsigned integer quotient of the two operands.
+Note that unsigned integer division and signed integer division are distinct +operations; for signed integer division, use 'sdiv'.
+Division by zero leads to undefined behavior.
Example:
<result> = udiv i32 4, %var ; yields {i32}:result = 4 / %var@@ -2147,9 +2164,12 @@ operands. 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.
+The value produced is the signed integer quotient of the two operands.
+Note that signed integer division and unsigned integer division are distinct +operations; for unsigned integer division, use 'udiv'.
+Division by zero leads to undefined behavior. Overflow also leads to +undefined behavior; this is a rare case, but can occur, for example, +by doing a 32-bit division of -2147483648 by -1.
Example:
<result> = sdiv i32 4, %var ; yields {i32}:result = 4 / %var@@ -2194,6 +2214,9 @@ of the values in which case the elements must be integers.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.
+Note that unsigned integer remainder and signed integer remainder are +distinct operations; for signed integer remainder, use 'srem'.
+Taking the remainder of a division by zero leads to undefined behavior.
Example:
<result> = urem i32 4, %var ; yields {i32}:result = 4 % %var@@ -2225,6 +2248,14 @@ a value. For more information about the difference, see . For a table of how this is implemented in various languages, please see Wikipedia: modulo operation. +Note that signed integer remainder and unsigned integer remainder are +distinct operations; for unsigned integer remainder, use 'urem'.
+Taking the remainder of a division by zero leads to undefined behavior. +Overflow also leads to undefined behavior; this is a rare case, but can occur, +for example, by taking the remainder of a 32-bit division of -2147483648 by -1. +(The remainder doesn't actually overflow, but this rule lets srem be +implemented using instructions that return both the result of the division +and the remainder.)
Example:
<result> = srem i32 4, %var ; yields {i32}:result = 4 % %var