Skip to content

Commit

Permalink
[mlir][tosa] Fix clamp float lowering
Browse files Browse the repository at this point in the history
min and max were mixed up after switching to using float min/max

Differential Revision: https://reviews.llvm.org/D131923
  • Loading branch information
ThomasRaoux committed Aug 15, 2022
1 parent 73f0ca8 commit 444b4fd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/Tosa/Utils/ConversionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 444b4fd

Please sign in to comment.