[Mlir-commits] [mlir] d5a4c86 - [mlir][tosa] tosa.cast support for unsigned integers

Rob Suderman llvmlistbot at llvm.org
Tue Oct 5 10:59:09 PDT 2021


Author: Rob Suderman
Date: 2021-10-05T10:57:16-07:00
New Revision: d5a4c86d14488baee9c42c45b27c3addb8877624

URL: https://github.com/llvm/llvm-project/commit/d5a4c86d14488baee9c42c45b27c3addb8877624
DIFF: https://github.com/llvm/llvm-project/commit/d5a4c86d14488baee9c42c45b27c3addb8877624.diff

LOG: [mlir][tosa] tosa.cast support for unsigned integers

Unsigned integers need to be handled for cast to floating point.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D111102

Added: 
    

Modified: 
    mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
    mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
index 1d4132fddbfc7..77e4c267bfbf1 100644
--- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
+++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
@@ -566,6 +566,19 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
       return rewriter.create<mlir::SIToFPOp>(loc, resultTypes, args,
                                              mlir::None);
 
+    // Unsigned integers need an unrealized cast so that they can be passed
+    // to UIToFP.
+    if (srcTy.isUnsignedInteger() && dstTy.isa<FloatType>()) {
+      auto unrealizedCast =
+          rewriter
+              .create<UnrealizedConversionCastOp>(
+                  loc, rewriter.getIntegerType(srcTy.getIntOrFloatBitWidth()),
+                  args[0])
+              .getResult(0);
+      return rewriter.create<mlir::UIToFPOp>(loc, resultTypes[0],
+                                             unrealizedCast);
+    }
+
     // Casting to boolean, floats need to only be checked as not-equal to zero.
     if (srcTy.isa<FloatType>() && dstTy.isInteger(1)) {
       Value zero =

diff  --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
index 4209172b27478..ba9b0d25ab5c4 100644
--- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
+++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
@@ -432,6 +432,18 @@ func @test_simple_i32(%arg0: tensor<1xi32>) -> () {
 
 // -----
 
+// CHECK-LABEL: @test_simple_ui8
+func @test_simple_ui8(%arg0: tensor<1xui8>) -> () {
+
+  // CHECK: linalg.generic
+  // CHECK: uitofp
+  %0 = "tosa.cast"(%arg0) : (tensor<1xui8>) -> tensor<1xf32>
+
+  return
+}
+
+// -----
+
 // CHECK-LABEL: @test_i8
 func @test_i8(%arg0: tensor<1xi8>) -> () {
   // CHECK: linalg.generic


        


More information about the Mlir-commits mailing list