Skip to content

Commit 444b4fd

Browse files
committed
[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
1 parent 73f0ca8 commit 444b4fd

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

mlir/lib/Dialect/Tosa/Utils/ConversionUtils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ mlir::tosa::condenseValues(const SmallVector<Value> &values) {
3232
Value mlir::tosa::clampFloatHelper(Location loc, Value arg,
3333
arith::ConstantOp min, arith::ConstantOp max,
3434
OpBuilder &rewriter) {
35-
Value minValue = rewriter.create<arith::MinFOp>(loc, arg, min);
36-
return rewriter.create<arith::MaxFOp>(loc, minValue, max);
35+
Value minValue = rewriter.create<arith::MinFOp>(loc, arg, max);
36+
return rewriter.create<arith::MaxFOp>(loc, minValue, min);
3737
}
3838

3939
Value mlir::tosa::clampIntHelper(Location loc, Value arg, arith::ConstantOp min,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ func.func @test_clamp_f16(%arg0: tensor<1xf16>) -> () {
467467
// CHECK: ^bb0(%[[ARG1:.+]]: f16,
468468
// CHECK-DAG: %[[C0:.+]] = arith.constant 0.0
469469
// CHECK-DAG: %[[C6:.+]] = arith.constant 6.0
470-
// CHECK-DAG: %[[MIN:.+]] = arith.minf %[[ARG1]], %[[C0]]
471-
// CHECK-DAG: %[[MAX:.+]] = arith.maxf %[[MIN]], %[[C6]]
470+
// CHECK-DAG: %[[MIN:.+]] = arith.minf %[[ARG1]], %[[C6]]
471+
// CHECK-DAG: %[[MAX:.+]] = arith.maxf %[[MIN]], %[[C0]]
472472
%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>
473473

474474
return

0 commit comments

Comments
 (0)