2050  2050 
Semantics: 
2051  2051 
The value produced is the integer or floating point sum of the two 
2052  2052  operands. 
2053 
If an integer sum has unsigned overflow, the result returned is the 

2054  mathematical result modulo 2^{n}, where n is the bit width of  
2055  the result.  
2056 
Because LLVM integers use a two's complement representation, this 

2057  instruction is appropriate for both signed and unsigned integers.  
2053  2058 
Example: 
2054  2059 
<result> = add i32 4, %var ; yields {i32}:result = 4 + %var 
2055  2060  
2075  2080 
Semantics: 
2076  2081 
The value produced is the integer or floating point difference of 
2077  2082  the two operands. 
2083 
If an integer difference has unsigned overflow, the result returned is the 

2084  mathematical result modulo 2^{n}, where n is the bit width of  
2085  the result.  
2086 
Because LLVM integers use a two's complement representation, this 

2087  instruction is appropriate for both signed and unsigned integers.  
2078  2088 
Example: 
2079  2089 

2080  2090  <result> = sub i32 4, %var ; yields {i32}:result = 4  %var 
2100  2110 
Semantics: 
2101  2111 
The value produced is the integer or floating point product of the 
2102  2112  two operands. 
2103 
Because the operands are the same width, the result of an integer 

2104  multiplication is the same whether the operands should be deemed unsigned or  
2105  signed.⏎  
2113 
If the result of an integer multiplication has unsigned overflow,⏎ 

2114  the result returned is the mathematical result modulo  
2115  2^{n}, where n is the bit width of the result.  
2116 
Because LLVM integers use a two's complement representation, and the 

2117  result is the same width as the operands, this instruction returns the  
2118  correct result for both signed and unsigned integers. If a full product  
2119  (e.g. i32xi32>i64) is needed, the operands  
2120  should be signextended or zeroextended as appropriate to the  
2121  width of the full product.  
2106  2122 
Example: 
2107  2123 
<result> = mul i32 4, %var ; yields {i32}:result = 4 * %var 
2108  2124  
2123  2139  types. This instruction can also take vector versions 
2124  2140  of the values in which case the elements must be integers. 
2125  2141 
Semantics: 
2126 
The value produced is the unsigned integer quotient of the two operands. This 

2127  instruction always performs an unsigned division operation, regardless of  
2128 


2142 
The value produced is the unsigned integer quotient of the two operands. ⏎ 

2143 
Note that unsigned integer division and signed integer division are distinct 

2144  operations; for signed integer division, use 'sdiv'.  
2145 
Division by zero leads to undefined behavior. 

2129  2146 
Example: 
2130  2147 
<result> = udiv i32 4, %var ; yields {i32}:result = 4 / %var 
2131  2148  
2146  2163  types. This instruction can also take vector versions 
2147  2164  of the values in which case the elements must be integers. 
2148  2165 
Semantics: 
2149 
The value produced is the signed integer quotient of the two operands. This 

2150  instruction always performs a signed division operation, regardless of whether  
2151 


2166 
The value produced is the signed integer quotient of the two operands. ⏎ 

2167 
Note that signed integer division and unsigned integer division are distinct 

2168  operations; for unsigned integer division, use 'udiv'.  
2169 
Division by zero leads to undefined behavior. Overflow also leads to 

2170  undefined behavior; this is a rare case, but can occur, for example,  
2171  by doing a 32bit division of 2147483648 by 1.  
2152  2172 
Example: 
2153  2173 
<result> = sdiv i32 4, %var ; yields {i32}:result = 4 / %var 
2154  2174  
2193  2213 
This instruction returns the unsigned integer remainder of a division. 
2194  2214  This instruction always performs an unsigned division to get the remainder, 
2195  2215  regardless of whether the arguments are unsigned or not. 
2216 
Note that unsigned integer remainder and signed integer remainder are 

2217  distinct operations; for signed integer remainder, use 'srem'.  
2218 
Taking the remainder of a division by zero leads to undefined behavior. 

2196  2219 
Example: 
2197  2220 
<result> = urem i32 4, %var ; yields {i32}:result = 4 % %var 
2198  2221  
2224  2247  Math Forum. For a table of how this is implemented in various languages, 
2225  2248  please see 
2226  2249  Wikipedia: modulo operation. 
2250 
Note that signed integer remainder and unsigned integer remainder are 

2251  distinct operations; for unsigned integer remainder, use 'urem'.  
2252 
Taking the remainder of a division by zero leads to undefined behavior. 

2253  Overflow also leads to undefined behavior; this is a rare case, but can occur,  
2254  for example, by taking the remainder of a 32bit division of 2147483648 by 1.  
2255  (The remainder doesn't actually overflow, but this rule lets srem be  
2256  implemented using instructions that return both the result of the division  
2257  and the remainder.)  
2227  2258 
Example: 
2228  2259 
<result> = srem i32 4, %var ; yields {i32}:result = 4 % %var 
2229  2260 