From: Rob Suderman Date: Mon, 3 May 2021 20:56:00 +0000 (-0700) Subject: [mlir][tosa] Add lowering to tosa.abs for integer cases X-Git-Tag: llvmorg-14-init~6747 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f97d970a49fb1f95cd3ac599369e53325129f769;p=platform%2Fupstream%2Fllvm.git [mlir][tosa] Add lowering to tosa.abs for integer cases Integer case requires decomposing to simple LLVM operatons. Differential Revision: https://reviews.llvm.org/D101809 --- diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp index 3934690..06b23cc 100644 --- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp +++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp @@ -102,6 +102,15 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args, if (isa(op) && elementTy.isa()) return rewriter.create(loc, resultTypes, args); + if (isa(op) && elementTy.isa()) { + auto zero = + rewriter.create(loc, rewriter.getZeroAttr(elementTy)); + auto cmp = + rewriter.create(loc, CmpIPredicate::sgt, args[0], zero); + auto neg = rewriter.create(loc, zero, args[0]); + return rewriter.create(loc, cmp, args[0], neg); + } + // tosa::AddOp if (isa(op) && elementTy.isa()) return rewriter.create(loc, resultTypes, args); diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir index 1e250c8..c2e6b07 100644 --- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir +++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir @@ -400,6 +400,13 @@ func @test_simple_i32(%arg0: tensor<1xi32>) -> () { // CHECK: sitofp %24 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xf32> + // CHECK: linalg.generic + // CHECK: constant 0 + // CHECK: cmpi sgt + // CHECK: subi + // CHECK: select + %25 = "tosa.abs"(%arg0) : (tensor<1xi32>) -> tensor<1xi32> + return }