[Mlir-commits] [mlir] 89a1af7 - [mlir][tosa] TosaToLinalg: Lower TOSA.Cast via RoundEven according to TOSA spec 0.60.0
Robert Suderman
llvmlistbot at llvm.org
Wed Mar 22 18:54:54 PDT 2023
Author: Matthias Gehre
Date: 2023-03-23T01:52:26Z
New Revision: 89a1af749166627704cdf9d676455d32616c2c06
URL: https://github.com/llvm/llvm-project/commit/89a1af749166627704cdf9d676455d32616c2c06
DIFF: https://github.com/llvm/llvm-project/commit/89a1af749166627704cdf9d676455d32616c2c06.diff
LOG: [mlir][tosa] TosaToLinalg: Lower TOSA.Cast via RoundEven according to TOSA spec 0.60.0
TOSA now specifies rounding of ties to even in section 1.8.2., "Main Inference Profile"
Reviewed By: eric-k256, rsuderman
Differential Revision: https://reviews.llvm.org/D146617
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 271a09539e46e..be24f5ee5feb4 100644
--- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
+++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
@@ -471,11 +471,6 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
}
if (arith::FPToSIOp::areCastCompatible(srcTy, dstTy)) {
- auto zero = rewriter.create<arith::ConstantOp>(
- loc, rewriter.getF32FloatAttr(0.0f));
- auto half = rewriter.create<arith::ConstantOp>(
- loc, rewriter.getF32FloatAttr(0.5f));
-
auto intMin = rewriter.create<arith::ConstantOp>(
loc, rewriter.getF32FloatAttr(
APInt::getSignedMinValue(dstTy.getIntOrFloatBitWidth())
@@ -486,12 +481,7 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
APInt::getSignedMaxValue(dstTy.getIntOrFloatBitWidth())
.getSExtValue()));
- auto added = rewriter.create<arith::AddFOp>(loc, args[0], half);
- auto subbed = rewriter.create<arith::SubFOp>(loc, args[0], half);
- auto negative = rewriter.create<arith::CmpFOp>(
- loc, arith::CmpFPredicate::OLT, args[0], zero);
- auto rounded =
- rewriter.create<arith::SelectOp>(loc, negative, subbed, added);
+ auto rounded = rewriter.create<math::RoundEvenOp>(loc, args[0]);
auto clamped = clampFloatHelper(loc, rounded, intMin, intMax, rewriter);
diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
index 133999eff1ec3..476131b262fb9 100644
--- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
+++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
@@ -237,14 +237,9 @@ func.func @test_simple_f32(%arg0: tensor<1xf32>) -> () {
%19 = "tosa.sigmoid"(%0) : (tensor<1xf32>) -> tensor<1xf32>
// CHECK: linalg.generic
- // CHECK: arith.constant 0.000000e+00
- // CHECK: arith.constant 5.000000e-01
// CHECK: arith.constant -2.14748365E+9
// CHECK: arith.constant 2.14748365E+9
- // CHECK: arith.addf
- // CHECK: arith.subf
- // CHECK: arith.cmpf olt
- // CHECK: select
+ // CHECK: math.roundeven
// CHECK: arith.minf
// CHECK: arith.maxf
// CHECK: arith.fptosi
More information about the Mlir-commits
mailing list