forked from OSchip/llvm-project
[mlir][tosa] Add tosa.logical_* to linalg lowerings
Adds lowerings for logical_* boolean operations. Each of these ops only operate on booleans allowing simple lowerings. Reviewed By: NatashaKnk Differential Revision: https://reviews.llvm.org/D98910
This commit is contained in:
parent
a2e0312cda
commit
1b7498120d
|
@ -149,10 +149,29 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
|
|||
if (isa<tosa::LogicalLeftShiftOp>(op) && elementTy.isa<IntegerType>())
|
||||
return rewriter.create<mlir::ShiftLeftOp>(loc, resultTypes, args);
|
||||
|
||||
// tosa::LogicalrightShiftOp
|
||||
// tosa::LogicalRightShiftOp
|
||||
if (isa<tosa::LogicalRightShiftOp>(op) && elementTy.isa<IntegerType>())
|
||||
return rewriter.create<mlir::UnsignedShiftRightOp>(loc, resultTypes, args);
|
||||
|
||||
// tosa::LogicalAnd
|
||||
if (isa<tosa::LogicalAndOp>(op) && elementTy.isInteger(1))
|
||||
return rewriter.create<mlir::AndOp>(loc, resultTypes, args);
|
||||
|
||||
// tosa::LogicalNot
|
||||
if (isa<tosa::LogicalNotOp>(op) && elementTy.isInteger(1)) {
|
||||
auto one = rewriter.create<mlir::ConstantOp>(
|
||||
loc, rewriter.getIntegerAttr(elementTy, 1));
|
||||
return rewriter.create<mlir::XOrOp>(loc, resultTypes, args[0], one);
|
||||
}
|
||||
|
||||
// tosa::LogicalOr
|
||||
if (isa<tosa::LogicalOrOp>(op) && elementTy.isInteger(1))
|
||||
return rewriter.create<mlir::OrOp>(loc, resultTypes, args);
|
||||
|
||||
// tosa::LogicalXor
|
||||
if (isa<tosa::LogicalXorOp>(op) && elementTy.isInteger(1))
|
||||
return rewriter.create<mlir::XOrOp>(loc, resultTypes, args);
|
||||
|
||||
// tosa::PowOp
|
||||
if (isa<tosa::PowOp>(op) && elementTy.isa<FloatType>())
|
||||
return rewriter.create<mlir::math::PowFOp>(loc, resultTypes, args);
|
||||
|
@ -869,6 +888,10 @@ void mlir::tosa::populateTosaToLinalgOnTensorsConversionPatterns(
|
|||
PointwiseConverter<tosa::BitwiseAndOp>,
|
||||
PointwiseConverter<tosa::BitwiseOrOp>,
|
||||
PointwiseConverter<tosa::BitwiseXorOp>,
|
||||
PointwiseConverter<tosa::LogicalAndOp>,
|
||||
PointwiseConverter<tosa::LogicalNotOp>,
|
||||
PointwiseConverter<tosa::LogicalOrOp>,
|
||||
PointwiseConverter<tosa::LogicalXorOp>,
|
||||
PointwiseConverter<tosa::LogicalLeftShiftOp>,
|
||||
PointwiseConverter<tosa::LogicalRightShiftOp>,
|
||||
PointwiseConverter<tosa::SelectOp>, PointwiseConverter<tosa::GreaterOp>,
|
||||
|
|
|
@ -260,6 +260,30 @@ func @test_simple_i32(%arg0: tensor<1xi32>) -> () {
|
|||
|
||||
// -----
|
||||
|
||||
// CHECK-LABEL: @test_bool
|
||||
func @test_bool(%arg0: tensor<1xi1>, %arg1: tensor<1xi1>) -> () {
|
||||
// CHECK: linalg.generic
|
||||
// CHECK: and
|
||||
%0 = "tosa.logical_and"(%arg0, %arg1) : (tensor<1xi1>, tensor<1xi1>) -> tensor<1xi1>
|
||||
|
||||
// CHECK: linalg.generic
|
||||
// CHECK: or
|
||||
%1 = "tosa.logical_or"(%arg0, %arg1) : (tensor<1xi1>, tensor<1xi1>) -> tensor<1xi1>
|
||||
|
||||
// CHECK: linalg.generic
|
||||
// CHECK: xor
|
||||
%2 = "tosa.logical_xor"(%arg0, %arg1) : (tensor<1xi1>, tensor<1xi1>) -> tensor<1xi1>
|
||||
|
||||
// CHECK: linalg.generic
|
||||
// CHECK: constant true
|
||||
// CHECK: xor
|
||||
%3 = "tosa.logical_not"(%arg0) : (tensor<1xi1>) -> tensor<1xi1>
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// CHECK: #[[$MAP0:.*]] = affine_map<(d0, d1) -> (d0, d1)>
|
||||
// CHECK-LABEL: @test_reshape_downrank
|
||||
func @test_reshape_downrank(%arg0: tensor<2x3xf32>) -> tensor<6xf32> {
|
||||
|
|
Loading…
Reference in New Issue