Skip to content

Commit

Permalink
TosaToLinalg: fix tosa.cast INT_MAX overflow constant (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
cferry-AMD authored Jun 21, 2024
1 parent f619673 commit 3e76eaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ static Value createLinalgBodyCalculationForElementwiseOp(
loc, rewriter.getFloatAttr(
getElementTypeOrSelf(srcTy),
APInt::getSignedMaxValue(dstTy.getIntOrFloatBitWidth())
.getSExtValue() +
.getZExtValue() +
1));

auto intMax = rewriter.create<arith::ConstantOp>(
Expand Down
11 changes: 11 additions & 0 deletions mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,17 @@ func.func @test_simple_f32(%arg0: tensor<1xf32>) -> () {
// CHECK: arith.fptoui
%u20 = tosa.cast %0 : (tensor<1xf32>) -> tensor<1xui32>

// CHECK: linalg.generic
// CHECK: [[ROUND:%.+]] = math.roundeven {{%.+}} : f32
// CHECK: [[CSTMIN:%.+]] = arith.constant -9.22337203E+18 : f32
// CHECK: [[CSTMAXP1:%.+]] = arith.constant 9.22337203E+18 : f32
// CHECK: [[CSTMAX:%.+]] = arith.constant 9223372036854775807 : i64
// CHECK: [[MAX:%.+]] = arith.maximumf [[ROUND]], [[CSTMIN]] : f32
// CHECK: [[CONV:%.+]] = arith.fptosi [[MAX]] : f32 to i64
// CHECK: [[CMP:%.+]] = arith.cmpf uge, [[ROUND]], [[CSTMAXP1]] : f32
// CHECK: arith.select [[CMP]], [[CSTMAX]], [[CONV]] : i64
%cast_f32_i64 = tosa.cast %0 : (tensor<1xf32>) -> tensor<1xi64>

// CHECK: linalg.generic
// CHECK: arith.constant 0
// CHECK: arith.cmpf
Expand Down

0 comments on commit 3e76eaa

Please sign in to comment.