[Mlir-commits] [mlir] a28fe17 - [mlir] Add EqualOp and NotEqualOp to complex dialect.

Adrian Kuegel llvmlistbot at llvm.org
Thu May 20 04:25:44 PDT 2021


Author: Adrian Kuegel
Date: 2021-05-20T13:25:07+02:00
New Revision: a28fe17d7315f72b802b4ac4b4bc1603ffe7a23b

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

LOG: [mlir] Add EqualOp and NotEqualOp to complex dialect.

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
    mlir/lib/Dialect/Complex/IR/ComplexOps.cpp
    mlir/test/Dialect/Complex/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td b/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
index efea0b284552e..bac349230a943 100644
--- a/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
+++ b/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
@@ -147,6 +147,29 @@ def ImOp : Complex_Op<"im",
   let hasFolder = 1;
 }
 
+//===----------------------------------------------------------------------===//
+// EqualOp
+//===----------------------------------------------------------------------===//
+
+def EqualOp : Complex_Op<"eq",
+    [NoSideEffect, AllTypesMatch<["lhs", "rhs"]>]> {
+  let summary = "computes whether two complex values are equal";
+  let description = [{
+    The `eq` op takes two complex numbers and returns whether they are equal.
+
+    Example:
+
+    ```mlir
+    %a = complex.eq %b, %c : complex<f32>
+    ```
+  }];
+
+  let arguments = (ins Complex<AnyFloat>:$lhs, Complex<AnyFloat>:$rhs);
+  let results = (outs I1:$result);
+
+  let assemblyFormat = "$lhs `,` $rhs  attr-dict `:` type($lhs)";
+}
+
 //===----------------------------------------------------------------------===//
 // MulOp
 //===----------------------------------------------------------------------===//
@@ -162,6 +185,30 @@ def MulOp : ComplexArithmeticOp<"mul"> {
   }];
 }
 
+//===----------------------------------------------------------------------===//
+// NotEqualOp
+//===----------------------------------------------------------------------===//
+
+def NotEqualOp : Complex_Op<"neq",
+    [NoSideEffect, AllTypesMatch<["lhs", "rhs"]>]> {
+  let summary = "computes whether two complex values are not equal";
+  let description = [{
+    The `neq` op takes two complex numbers and returns whether they are not
+    equal.
+
+    Example:
+
+    ```mlir
+    %a = complex.neq %b, %c : complex<f32>
+    ```
+  }];
+
+  let arguments = (ins Complex<AnyFloat>:$lhs, Complex<AnyFloat>:$rhs);
+  let results = (outs I1:$result);
+
+  let assemblyFormat = "$lhs `,` $rhs  attr-dict `:` type($lhs)";
+}
+
 //===----------------------------------------------------------------------===//
 // ReOp
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/Dialect/Complex/IR/ComplexOps.cpp b/mlir/lib/Dialect/Complex/IR/ComplexOps.cpp
index c0dcabe992cb8..cf89508c64c75 100644
--- a/mlir/lib/Dialect/Complex/IR/ComplexOps.cpp
+++ b/mlir/lib/Dialect/Complex/IR/ComplexOps.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "mlir/Dialect/Complex/IR/Complex.h"
+#include "mlir/IR/Builders.h"
 
 using namespace mlir;
 using namespace mlir::complex;

diff  --git a/mlir/test/Dialect/Complex/ops.mlir b/mlir/test/Dialect/Complex/ops.mlir
index 9685886ee5250..09d31ba400f4f 100644
--- a/mlir/test/Dialect/Complex/ops.mlir
+++ b/mlir/test/Dialect/Complex/ops.mlir
@@ -23,6 +23,12 @@ func @ops(%f: f32) {
   // CHECK: complex.div %[[C]], %[[C]] : complex<f32>
   %div = complex.div %complex, %complex : complex<f32>
 
+  // CHECK: complex.eq %[[C]], %[[C]] : complex<f32>
+  %eq = complex.eq %complex, %complex : complex<f32>
+
+  // CHECK: complex.neq %[[C]], %[[C]] : complex<f32>
+  %neq = complex.neq %complex, %complex : complex<f32>
+
   // CHECK: complex.mul %[[C]], %[[C]] : complex<f32>
   %prod = complex.mul %complex, %complex : complex<f32>
 


        


More information about the Mlir-commits mailing list