[Mlir-commits] [mlir] [Tosa] : Fix integer overflow for computing intmax+1 in tosa.cast to linalg. (PR #112455)
Sayan Saha
llvmlistbot at llvm.org
Tue Oct 15 17:33:02 PDT 2024
sahas3 wrote:
Without the fix the IR after `tosa-to-linalg` for
```
func.func @test_cast_fp32_i64(%arg0: tensor<1xf32>) -> (tensor<1xi64>) {
%0 = tosa.cast %arg0 : (tensor<1xf32>) -> tensor<1xi64>
return %0: tensor<1xi64>
}
```
was
```
#map = affine_map<(d0) -> (0)>
#map1 = affine_map<(d0) -> (d0)>
module {
func.func @test_cast_fp32_i64(%arg0: tensor<1xf32>) -> tensor<1xui64> {
%0 = tensor.empty() : tensor<1xi64>
%1 = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel"]} ins(%arg0 : tensor<1xf32>) outs(%0 : tensor<1xi64>) {
^bb0(%in: f32, %out: i64):
%3 = math.roundeven %in : f32
%cst = arith.constant -9.22337203E+18 : f32
%cst_0 = arith.constant -9.22337203E+18 : f32
%c9223372036854775807_i64 = arith.constant 9223372036854775807 : i64
%4 = arith.maximumf %3, %cst : f32
%5 = arith.fptosi %4 : f32 to i64
%6 = arith.cmpf uge, %3, %cst_0 : f32
%7 = arith.select %6, %c9223372036854775807_i64, %5 : i64
linalg.yield %7 : i64
} -> tensor<1xi64>
%2 = builtin.unrealized_conversion_cast %1 : tensor<1xi64> to tensor<1xui64>
return %2 : tensor<1xui64>
}
}
```
https://github.com/llvm/llvm-project/pull/112455
More information about the Mlir-commits
mailing list