[Mlir-commits] [mlir] [mlir][arith] Add `exact` to `index_cast{, ui}` (PR #183395)
Erick Ochoa Lopez
llvmlistbot at llvm.org
Tue Mar 3 13:01:59 PST 2026
================
@@ -288,31 +288,38 @@ def SelectI1ToNot :
// IndexCastOp
//===----------------------------------------------------------------------===//
-// index_cast(index_cast(x)) -> x, if dstType == srcType.
+// index_cast(index_cast(x, exact)) -> x, if dstType == srcType.
----------------
amd-eochoalo wrote:
> After this change, the fold seems to require exact, even for this widening/narrowing pattern which is typically non-lossy in practice.
Yes, you are right. This pattern is more restrictive. I think if we want to have both, we should probably have two patterns. One for narrowing/widening that checks for exact. And another for widening/narrowing which doesn't require it.
Please note that the previous pattern (which applied for both widening/narrowing, narrowing/widening) was unsound. Consider the case:
```
index = i8 // to make the typing smaller
%x = index_cast 0x100 : i16 to index
%y = index_cast %x : index to i16
```
https://github.com/llvm/llvm-project/pull/183395
More information about the Mlir-commits
mailing list