[Mlir-commits] [mlir] [mlir][arith] Add `exact` to `index_cast{, ui}` (PR #183395)
Slava Zakharin
llvmlistbot at llvm.org
Fri Feb 27 17:06:42 PST 2026
================
@@ -1579,15 +1580,34 @@ def IndexCastTypeConstraint : TypeConstraint<Or<[
def Arith_IndexCastOp
: Arith_CastOp<"index_cast", IndexCastTypeConstraint, IndexCastTypeConstraint,
- [DeclareOpInterfaceMethods<InferIntRangeInterface, ["inferResultRanges"]>]> {
+ [DeclareOpInterfaceMethods<InferIntRangeInterface, ["inferResultRanges"]>,
+ DeclareOpInterfaceMethods<ArithExactFlagInterface>]> {
let summary = "cast between index and integer types";
let description = [{
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.
+
+ If the `exact` attribute is present, it is assumed that the operand
+ contains a value that fits in the destination's representation, therefore
+ the cast does not lose any information. When this assumption is violated,
+ the result is poison.
+
+ Example:
+
+ ```mlir
+ %0 = arith.index_cast %a : index to i64
+ %1 = arith.index_cast %a exact : index to i64
+ %2 = arith.index_cast %b exact : i32 to index
+ ```
}];
+ let arguments = (ins IndexCastTypeConstraint:$in, UnitAttr:$isExact);
----------------
vzakhari wrote:
Okay, you may ignore my comment. Since it does not trigger the immediate UB, it should be okay. Thanks!
https://github.com/llvm/llvm-project/pull/183395
More information about the Mlir-commits
mailing list