forked from OSchip/llvm-project
[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
This commit is contained in:
parent
b47539a14d
commit
f97d970a49
|
@ -102,6 +102,15 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
|
|||
if (isa<tosa::AbsOp>(op) && elementTy.isa<FloatType>())
|
||||
return rewriter.create<mlir::AbsFOp>(loc, resultTypes, args);
|
||||
|
||||
if (isa<tosa::AbsOp>(op) && elementTy.isa<IntegerType>()) {
|
||||
auto zero =
|
||||
rewriter.create<mlir::ConstantOp>(loc, rewriter.getZeroAttr(elementTy));
|
||||
auto cmp =
|
||||
rewriter.create<mlir::CmpIOp>(loc, CmpIPredicate::sgt, args[0], zero);
|
||||
auto neg = rewriter.create<mlir::SubIOp>(loc, zero, args[0]);
|
||||
return rewriter.create<mlir::SelectOp>(loc, cmp, args[0], neg);
|
||||
}
|
||||
|
||||
// tosa::AddOp
|
||||
if (isa<tosa::AddOp>(op) && elementTy.isa<FloatType>())
|
||||
return rewriter.create<mlir::AddFOp>(loc, resultTypes, args);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue