Skip to content

Commit 76dc9a8

Browse files
mariecwhitersuderman
authored andcommitted
[mlir][tosa] Remove clamping behavior in tosa.cast for integer truncation
Reviewed By: rsuderman Differential Revision: https://reviews.llvm.org/D141015
1 parent 4e02ff2 commit 76dc9a8

File tree

2 files changed

+1
-20
lines changed

2 files changed

+1
-20
lines changed

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -512,20 +512,7 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
512512
std::nullopt);
513513

514514
if (srcTy.isa<IntegerType>() && dstTy.isa<IntegerType>() && !bitExtend) {
515-
auto intMin = rewriter.create<arith::ConstantIntOp>(
516-
loc,
517-
APInt::getSignedMinValue(dstTy.getIntOrFloatBitWidth())
518-
.getSExtValue(),
519-
srcTy.getIntOrFloatBitWidth());
520-
521-
auto intMax = rewriter.create<arith::ConstantIntOp>(
522-
loc,
523-
APInt::getSignedMaxValue(dstTy.getIntOrFloatBitWidth())
524-
.getSExtValue(),
525-
srcTy.getIntOrFloatBitWidth());
526-
527-
auto clamped = clampIntHelper(loc, args[0], intMin, intMax, rewriter);
528-
return rewriter.create<arith::TruncIOp>(loc, dstTy, clamped);
515+
return rewriter.create<arith::TruncIOp>(loc, dstTy, args[0]);
529516
}
530517
}
531518

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,6 @@ func.func @test_simple_i32(%arg0: tensor<1xi32>) -> () {
400400
%19 = "tosa.clamp"(%0) {min_int = 1 : i64, max_int = 5 : i64, min_fp = 1.0 : f32, max_fp = 5.0 : f32} : (tensor<1xi32>) -> tensor<1xi32>
401401

402402
// CHECK: linalg.generic
403-
// CHECK: arith.constant -32768
404-
// CHECK: arith.constant 32767
405-
// CHECK: arith.cmpi slt
406-
// CHECK: select
407-
// CHECK: arith.cmpi slt
408-
// CHECK: select
409403
// CHECK: arith.trunci
410404
%20 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xi16>
411405

0 commit comments

Comments
 (0)