Problem when lowering uint memref to std

We encounter a problem, when we lowering lmhlo::ConvertOp to std Dialect. This input type is uint8, output type is fp32.
The example mlir is just like this:

func @convert(%input: memref<?x?x?xui8>, %out: memref<?x?x?xf32>)->memref<?x?x?xf32>{
  "lmhlo.convert"(%input, %out) {} : (memref<?x?x?xui8>, memref<?x?x?xf32>) -> ()
  return %out : memref<?x?x?xf32>

But as this patch shows, UIToFPOp and SIToFPOp only accept SignlessInteger type. And we cannot convert the input memref to int8 beacuse memref::reinterpret_cast cannot change data type.
So we are wondering, whether we can:

  1. add a std.bitcast just like llvm.bitcast , or
  2. add unsigned and signed integer into the input type constraint for UIToFPOp and SIToFPOp.

We think the second method is simpler. How do you think about this, and maybe other suggestions?

std.bitcast is in progress - ⚙ D105376 [MLIR][std] Introduce bitcast operation, [RFC] Introduce a bitcast op

std.bitcast is not able to solve this problem since it still requires for signless interger type for both input & output.
I think the essential problem is that,

  • Frontend dialects like TF dialect or mhlo dialect requires for signed/unsigned semantics for their ops to function properly, like mhlo.convert;

  • Std dialect strictly requires for signless semantics (As in this doc: MLIR Rationale - MLIR).
    By this way, during the lowering of mhlo->std, the pass must also be able to properly terminate the signed/unsigned semantics, to explicitly convert the type from signed/unsigned into signless during the lowering.

This is not easy unless the pass is made of ConversionPatterns with a TypeConverter. (unfortunately it is not in our implementation). Without the help of a TypeConverter, I think memref.reinterpret_cast (or similar ops) would be a candidate that can greatly help to simplify this process. Without it it would be much more complicated. However, currently memref.reinterpret_cast requires for the element type to be strictly the same, which means it cannot do ui32->i32 cast. Is it possible if we give memref.reinterpret_cast the expressiveness to do signed/unsigned->signless cast?
Will there be any potential risks?

We are converting signed to signless when going from higher-level dialects (like mhlo) to lower level codegen dialects like standard, memref or linalg. For the mhlo to memref conversion, which converts from tensors to buffers and from signed to singless, we have a special kind of pattern that supports this double conversion. The conversion from mhlo to linalg uses conversion with a single converter and makes sure to pick the correct operation when lowering element wise ops. This is all based on a customized type converter.

Using bitcast would also be an option but if you want to do this manually, you could also just insert a builtin.unmaterlialized_conversion_cast, as you have to fully remove all signed types before going to LLVM anyway.

I recently faced the same issue as you, but since we already convert the type during lowering to Linalg, it was possible to work around the problem and create the UIToFPOp with the converted types.
Here was my change to add support for unsigned int casting (when lowering from hlo to linalg):