[mlir][tosa] Remove clamping behavior in `tosa.cast` for integer truncation
authormariecwhite <mariewhite@google.com>
Wed, 4 Jan 2023 22:56:45 +0000 (14:56 -0800)
committerRob Suderman <suderman@google.com>
Wed, 4 Jan 2023 23:10:06 +0000 (15:10 -0800)
Reviewed By: rsuderman

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

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

index 22563ea..7e12d1b 100644 (file)
@@ -512,20 +512,7 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
                                              std::nullopt);
 
     if (srcTy.isa<IntegerType>() && dstTy.isa<IntegerType>() && !bitExtend) {
-      auto intMin = rewriter.create<arith::ConstantIntOp>(
-          loc,
-          APInt::getSignedMinValue(dstTy.getIntOrFloatBitWidth())
-              .getSExtValue(),
-          srcTy.getIntOrFloatBitWidth());
-
-      auto intMax = rewriter.create<arith::ConstantIntOp>(
-          loc,
-          APInt::getSignedMaxValue(dstTy.getIntOrFloatBitWidth())
-              .getSExtValue(),
-          srcTy.getIntOrFloatBitWidth());
-
-      auto clamped = clampIntHelper(loc, args[0], intMin, intMax, rewriter);
-      return rewriter.create<arith::TruncIOp>(loc, dstTy, clamped);
+      return rewriter.create<arith::TruncIOp>(loc, dstTy, args[0]);
     }
   }
 
index 8406c05..864eec8 100644 (file)
@@ -400,12 +400,6 @@ func.func @test_simple_i32(%arg0: tensor<1xi32>) -> () {
   %19 = "tosa.clamp"(%0) {min_int = 1 : i64, max_int = 5 : i64, min_fp = 1.0 : f32, max_fp = 5.0 : f32} : (tensor<1xi32>) -> tensor<1xi32>
 
   // CHECK: linalg.generic
-  // CHECK: arith.constant -32768
-  // CHECK: arith.constant 32767
-  // CHECK: arith.cmpi slt
-  // CHECK: select
-  // CHECK: arith.cmpi slt
-  // CHECK: select
   // CHECK: arith.trunci
   %20 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xi16>