diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp index 34b6a8d6b10a7c..22c506ba303152 100644 --- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp +++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp @@ -61,7 +61,7 @@ static Value createLinalgBodyCalculationForElementwiseOp( if (isa(op) && isa(elementTy)) { auto zero = rewriter.create( - loc, rewriter.getZeroAttr(elementTy)); + loc, rewriter.getZeroAttr(convertedElementTy)); auto neg = rewriter.create(loc, zero, args[0]); return rewriter.create(loc, args[0], neg); } @@ -416,17 +416,19 @@ static Value createLinalgBodyCalculationForElementwiseOp( if (intTy.isUnsignedInteger()) { minRepresentable = 0; if (intTy.getIntOrFloatBitWidth() <= 63) { - maxRepresentable = (int64_t)APInt::getMaxValue(intTy.getIntOrFloatBitWidth()) - .getZExtValue(); + maxRepresentable = + (int64_t)APInt::getMaxValue(intTy.getIntOrFloatBitWidth()) + .getZExtValue(); } - } else if(intTy.getIntOrFloatBitWidth() <= 64) { + } else if (intTy.getIntOrFloatBitWidth() <= 64) { // Ensure that min & max fit into signed n-bit constants. minRepresentable = APInt::getSignedMinValue(intTy.getIntOrFloatBitWidth()) - .getSExtValue(); + .getSExtValue(); maxRepresentable = APInt::getSignedMaxValue(intTy.getIntOrFloatBitWidth()) - .getSExtValue(); + .getSExtValue(); } - // Ensure that the bounds are representable as n-bit signed/unsigned integers. + // Ensure that the bounds are representable as n-bit signed/unsigned + // integers. min = std::max(min, minRepresentable); max = std::max(max, minRepresentable); min = std::min(min, maxRepresentable); diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir index 1bf038cc69aef1..a09ca340e0813d 100644 --- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir +++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir @@ -2010,3 +2010,12 @@ func.func @test_dynamic_fft2d(%arg0: tensor, %arg1: tensor %output_real, %output_imag = "tosa.fft2d"(%arg0, %arg1) {inverse = true} : (tensor, tensor) -> (tensor, tensor) return %output_real, %output_imag : tensor, tensor } + +// ----- +// CHECK-LABEL: @test_abs_conversion +// CHECK: linalg.generic +// CHECK: arith.constant 0 : i64 +func.func @test_abs_conversion(%arg0: tensor<9xui64> {func.orig_type = tensor<9xui64>, onnx.name = "in0"}) -> (tensor<9xui64> {func.orig_type = tensor<9xui64>, onnx.name = "out0"}) { + %0 = tosa.abs %arg0 : (tensor<9xui64>) -> tensor<9xui64> + return %0 : tensor<9xui64> +}