Skip to content

Commit da49008

Browse files
committed
TosaToLinalg: Lower TOSA.Cast via RoundEven
1 parent 76dbb86 commit da49008

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,6 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
470470
}
471471

472472
if (arith::FPToSIOp::areCastCompatible(srcTy, dstTy)) {
473-
auto zero = rewriter.create<arith::ConstantOp>(
474-
loc, rewriter.getF32FloatAttr(0.0f));
475-
auto half = rewriter.create<arith::ConstantOp>(
476-
loc, rewriter.getF32FloatAttr(0.5f));
477-
478473
auto intMin = rewriter.create<arith::ConstantOp>(
479474
loc, rewriter.getF32FloatAttr(
480475
APInt::getSignedMinValue(dstTy.getIntOrFloatBitWidth())
@@ -485,12 +480,7 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
485480
APInt::getSignedMaxValue(dstTy.getIntOrFloatBitWidth())
486481
.getSExtValue()));
487482

488-
auto added = rewriter.create<arith::AddFOp>(loc, args[0], half);
489-
auto subbed = rewriter.create<arith::SubFOp>(loc, args[0], half);
490-
auto negative = rewriter.create<arith::CmpFOp>(
491-
loc, arith::CmpFPredicate::OLT, args[0], zero);
492-
auto rounded =
493-
rewriter.create<arith::SelectOp>(loc, negative, subbed, added);
483+
auto rounded = rewriter.create<math::RoundEvenOp>(loc, args[0]);
494484

495485
auto clamped = clampFloatHelper(loc, rounded, intMin, intMax, rewriter);
496486

0 commit comments

Comments
 (0)