[Mlir-commits] [mlir] Handled UnrealizedConversionCast for C code generation and validated tests (PR #160159)

Gil Rapaport llvmlistbot at llvm.org
Fri Oct 10 09:48:39 PDT 2025


aniragil wrote:

> From my understanding, I should modify the conversion to directly lower the input memref type to the !emitc.ptr<!emitc.array<...>> format and handle conversions using emitc::ApplyOp, ensuring that emitc::SubscriptOp supports the necessary index handling.

Right, except we were hoping you could use only `emitc.subscript` (by extending its existing support of `emitc.ptr` to multiple indices), thus avoiding the need to use `emitc.apply` as it would complicate things (right @simon-camp ?)

> 
> I just wanted to clarify one point — for cases like:
> 
> `builtin.unrealized_conversion_cast %arg0 : !emitc.size_t to index`
> 
> Would it make sense to handle the !emitc.size_t ↔ index conversion in a similar way within the TypeConverter? Specifically, by mapping index directly to !emitc.size_t and handling it uniformly during lowering, so we can avoid introducing UnrealizedConversionCastOp for these cases?
> 
> Would that approach be consistent with your suggestion?

@simon-camp is probably more qualified than me to answer concretely, but in general I think the answer is yes - we should avoid generating unrealized casts where possible (and AFAIK when they do get created they are usually created in pairs such that they cancel each other later). Is that related to the same problem you're fixing in this PR? If not, best to do that in a separate PR.

https://github.com/llvm/llvm-project/pull/160159


More information about the Mlir-commits mailing list