[Mlir-commits] [mlir] 444b4fd - [mlir][tosa] Fix clamp float lowering

Thomas Raoux llvmlistbot at llvm.org
Mon Aug 15 15:27:03 PDT 2022


Author: Thomas Raoux
Date: 2022-08-15T22:25:14Z
New Revision: 444b4fda17bca581fab084926b91393bd20478e7

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

LOG: [mlir][tosa] Fix clamp float lowering

min and max were mixed up after switching to using float min/max

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

Added: 
    

Modified: 
    mlir/lib/Dialect/Tosa/Utils/ConversionUtils.cpp
    mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Tosa/Utils/ConversionUtils.cpp b/mlir/lib/Dialect/Tosa/Utils/ConversionUtils.cpp
index 33999f3ad36ce..7f2e970f6b49b 100644
--- a/mlir/lib/Dialect/Tosa/Utils/ConversionUtils.cpp
+++ b/mlir/lib/Dialect/Tosa/Utils/ConversionUtils.cpp
@@ -32,8 +32,8 @@ mlir::tosa::condenseValues(const SmallVector<Value> &values) {
 Value mlir::tosa::clampFloatHelper(Location loc, Value arg,
                                    arith::ConstantOp min, arith::ConstantOp max,
                                    OpBuilder &rewriter) {
-  Value minValue = rewriter.create<arith::MinFOp>(loc, arg, min);
-  return rewriter.create<arith::MaxFOp>(loc, minValue, max);
+  Value minValue = rewriter.create<arith::MinFOp>(loc, arg, max);
+  return rewriter.create<arith::MaxFOp>(loc, minValue, min);
 }
 
 Value mlir::tosa::clampIntHelper(Location loc, Value arg, arith::ConstantOp min,

diff  --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
index c42c85e6462ab..6a49ba5e9e6ee 100644
--- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
+++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
@@ -467,8 +467,8 @@ func.func @test_clamp_f16(%arg0: tensor<1xf16>) -> () {
   // CHECK: ^bb0(%[[ARG1:.+]]: f16,
   // CHECK-DAG: %[[C0:.+]] = arith.constant 0.0
   // CHECK-DAG: %[[C6:.+]] = arith.constant 6.0
-  // CHECK-DAG: %[[MIN:.+]] = arith.minf %[[ARG1]], %[[C0]]
-  // CHECK-DAG: %[[MAX:.+]] = arith.maxf %[[MIN]], %[[C6]]
+  // CHECK-DAG: %[[MIN:.+]] = arith.minf %[[ARG1]], %[[C6]]
+  // CHECK-DAG: %[[MAX:.+]] = arith.maxf %[[MIN]], %[[C0]]
   %0 = "tosa.clamp"(%arg0) {min_int = 0 : i64, max_int = 0 : i64, min_fp = 0.0 : f32, max_fp = 6.0 : f32} : (tensor<1xf16>) -> tensor<1xf16>
 
   return


        


More information about the Mlir-commits mailing list