Skip to content

Commit 770d8db

Browse files
authored
Merge pull request #458 from Xilinx/bump_to_b91ce7bc
[AutoBump] Merge with fixes of b91ce7b (Oct 25) (2)
2 parents 43491d6 + 6de5a66 commit 770d8db

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,10 @@ static Value createLinalgBodyCalculationForElementwiseOp(
576576
auto intMaxPlusOneFP = rewriter.create<arith::ConstantOp>(
577577
loc, rewriter.getFloatAttr(
578578
getElementTypeOrSelf(srcTy),
579-
APInt::getSignedMaxValue(dstTy.getIntOrFloatBitWidth())
580-
.getZExtValue() +
581-
1));
579+
static_cast<double>(
580+
APInt::getSignedMaxValue(dstTy.getIntOrFloatBitWidth())
581+
.getSExtValue()) +
582+
1.0f));
582583

583584
auto intMax = rewriter.create<arith::ConstantOp>(
584585
loc, rewriter.getIntegerAttr(

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,3 +2026,28 @@ func.func @test_abs_conversion(%arg0: tensor<9xui64> {func.orig_type = tensor<9x
20262026
%0 = tosa.abs %arg0 : (tensor<9xui64>) -> tensor<9xui64>
20272027
return %0 : tensor<9xui64>
20282028
}
2029+
2030+
// -----
2031+
2032+
// CHECK: #[[$MAP:.+]] = affine_map<(d0) -> (d0)>
2033+
2034+
// CHECK-LABEL: func.func @test_cast_fp32_i64(
2035+
// CHECK-SAME: %[[ARG0:.*]]: tensor<1xf32>) -> tensor<1xi64> {
2036+
// CHECK: %[[EMPTY_TENSOR:.*]] = tensor.empty() : tensor<1xi64>
2037+
// CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP]], #[[$MAP]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<1xf32>) outs(%[[EMPTY_TENSOR]] : tensor<1xi64>) {
2038+
// CHECK: ^bb0(%[[IN:.*]]: f32, %[[OUT:.*]]: i64):
2039+
// CHECK: %[[ROUND_EVEN:.*]] = math.roundeven %[[IN]] : f32
2040+
// CHECK: %[[FP_INT_MIN:.*]] = arith.constant -9.22337203E+18 : f32
2041+
// CHECK: %[[FP_INT_MAX_PLUS_ONE:.*]] = arith.constant 9.22337203E+18 : f32
2042+
// CHECK: %[[INT_MAX:.*]] = arith.constant 9223372036854775807 : i64
2043+
// CHECK: %[[MAX:.*]] = arith.maximumf %[[ROUND_EVEN]], %[[FP_INT_MIN]] : f32
2044+
// CHECK: %[[FPTOSI:.*]] = arith.fptosi %[[MAX]] : f32 to i64
2045+
// CHECK: %[[CMPF:.*]] = arith.cmpf uge, %[[ROUND_EVEN]], %[[FP_INT_MAX_PLUS_ONE]] : f32
2046+
// CHECK: %[[SELECT:.*]] = arith.select %[[CMPF]], %[[INT_MAX]], %[[FPTOSI]] : i64
2047+
// CHECK: linalg.yield %[[SELECT]] : i64
2048+
// CHECK: } -> tensor<1xi64>
2049+
// CHECK: return %[[RESULT]] : tensor<1xi64>
2050+
func.func @test_cast_fp32_i64(%arg0: tensor<1xf32>) -> (tensor<1xi64>) {
2051+
%0 = tosa.cast %arg0 : (tensor<1xf32>) -> tensor<1xi64>
2052+
return %0: tensor<1xi64>
2053+
}

0 commit comments

Comments
 (0)