Type casting llvm.struct to memref

Hello.
I am trying to type cast an llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> to a memref<1000xf16> type.
If I try to use the llvm.bitcast MLIR instruction it gives the following error:
‘llvm.bitcast’ op operand #0 must be LLVM-compatible non-aggregate type, but got '!llvm.struct<(ptr, ptr, i64, array<1 xi64>, array<1 x i64>)>
Also the memref is not an LLVM-compatible non-aggregate type.

Could you please tell me if there is another MLIR instruction (maybe in a different dialect than LLVM) that can convert the llvm.struct to the memref.

Thank you,
Alex

The lowering from memref to LLVM struct is not a cast, so you can’t just bitcast the value back to memref. Upstream, AFAIK, there aren’t “raising” instruction from LLVM back to memref, so you’ll probably have to write one if you need this.

Polygeist doesn’t necessarily convert LLVM dialect into memref, but it handles both scf and LLVM dialects at the same time, so it might have some inspiration.

I don’t know of any other project that works at that level, but there may be some around.

If [RFC][memref] New op to (re)materialize a memref gets through, it could be combined with with llvm.extractvalue to implement the “cast”.

In the worst case, one can add an unrealized_conversion_cast and try to clean it up with -reconcile-unrealized-casts after the memref part is lowered to LLVM using the default lowering convention.

It has the polygeist.pointer2memref operation, but it operates under assumption that memrefs are only used to represent C-style pointers so their size is irrelevant.

Hello.
Thank you very much for both your answers. In the end I created a special call operation, which has the following arguments and results:
let arguments = (ins SymbolRefAttr:$c, Variadic:$opnds);
let results = (outs Variadic);
Best regards,
Alex