[Mlir-commits] [mlir] f5ba3ee - [mlir][tosa] Add tosa.bitwise_not lowering to constant and xor

Rob Suderman llvmlistbot at llvm.org
Wed Mar 24 17:29:07 PDT 2021


Author: Rob Suderman
Date: 2021-03-24T17:27:27-07:00
New Revision: f5ba3eea6746559513af7ed32db8083ad52661a3

URL: https://github.com/llvm/llvm-project/commit/f5ba3eea6746559513af7ed32db8083ad52661a3
DIFF: https://github.com/llvm/llvm-project/commit/f5ba3eea6746559513af7ed32db8083ad52661a3.diff

LOG: [mlir][tosa] Add tosa.bitwise_not lowering to constant and xor

Lowering of bitwise_not to linalg dialect using a xor operation with a constant
of all-bits-one.

Differential Revision: https://reviews.llvm.org/D99221

Added: 
    

Modified: 
    mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
index 2f6246e717eb..4dbd8879d6a0 100644
--- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
+++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
@@ -169,6 +169,14 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
   if (isa<tosa::BitwiseOrOp>(op) && elementTy.isa<IntegerType>())
     return rewriter.create<mlir::OrOp>(loc, resultTypes, args);
 
+  // tosa::BitwiseNotOp
+  if (isa<tosa::BitwiseNotOp>(op) && elementTy.isa<IntegerType>()) {
+    auto allOnesAttr = rewriter.getIntegerAttr(
+        elementTy, APInt::getAllOnesValue(elementTy.getIntOrFloatBitWidth()));
+    auto allOnes = rewriter.create<ConstantOp>(loc, allOnesAttr);
+    return rewriter.create<mlir::XOrOp>(loc, resultTypes, args[0], allOnes);
+  }
+
   // tosa::BitwiseXOrOp
   if (isa<tosa::BitwiseXorOp>(op) && elementTy.isa<IntegerType>())
     return rewriter.create<mlir::XOrOp>(loc, resultTypes, args);
@@ -441,13 +449,14 @@ elementwiseMatchAndRewriteHelper(Operation *operation,
         Value opResult = createLinalgBodyCalculationForElementwiseOp(
             operation, blockArgs.take_front(operation->getNumOperands()),
             bodyResultTypes, rewriter);
-        if (opResult) {
+        if (!opResult) {
           didEncounterError = true;
+          return;
         }
         nestedBuilder.create<linalg::YieldOp>(loc, opResult);
       });
 
-  if (!didEncounterError)
+  if (didEncounterError)
     return failure();
 
   rewriter.replaceOp(operation, linalgOp->getResults());
@@ -1379,6 +1388,7 @@ void mlir::tosa::populateTosaToLinalgOnTensorsConversionPatterns(
       PointwiseConverter<tosa::AbsOp>, PointwiseConverter<tosa::TanhOp>,
       PointwiseConverter<tosa::BitwiseAndOp>,
       PointwiseConverter<tosa::BitwiseOrOp>,
+      PointwiseConverter<tosa::BitwiseNotOp>,
       PointwiseConverter<tosa::BitwiseXorOp>,
       PointwiseConverter<tosa::LogicalAndOp>,
       PointwiseConverter<tosa::LogicalNotOp>,


        


More information about the Mlir-commits mailing list