aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/lib/Dialect/Test
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/test/lib/Dialect/Test')
-rw-r--r--mlir/test/lib/Dialect/Test/TestOps.td13
-rw-r--r--mlir/test/lib/Dialect/Test/TestPatterns.cpp10
2 files changed, 23 insertions, 0 deletions
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 6ea27187..6329d61 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -1169,6 +1169,11 @@ def OpP : TEST_Op<"op_p"> {
let results = (outs I32);
}
+def OpQ : TEST_Op<"op_q"> {
+ let arguments = (ins AnyType, AnyType);
+ let results = (outs AnyType);
+}
+
// Test constant-folding a pattern that maps `(F32) -> SI32`.
def SignOp : TEST_Op<"sign", [SameOperandsAndResultShape]> {
let arguments = (ins RankedTensorOf<[F32]>:$operand);
@@ -1207,6 +1212,14 @@ def TestNestedSameOpAndSameArgEqualityPattern :
def TestMultipleEqualArgsPattern :
Pat<(OpP $a, $b, $a, $a, $b, $c), (OpN $c, $b)>;
+// Test equal arguments checks are applied before user provided constraints.
+def AssertBinOpEqualArgsAndReturnTrue : Constraint<
+ CPred<"assertBinOpEqualArgsAndReturnTrue($0)">>;
+def TestEqualArgsCheckBeforeUserConstraintsPattern :
+ Pat<(OpQ:$op $x, $x),
+ (replaceWithValue $x),
+ [(AssertBinOpEqualArgsAndReturnTrue $op)]>;
+
// Test for memrefs normalization of an op with normalizable memrefs.
def OpNorm : TEST_Op<"op_norm", [MemRefsNormalizable]> {
let arguments = (ins AnyMemRef:$X, AnyMemRef:$Y);
diff --git a/mlir/test/lib/Dialect/Test/TestPatterns.cpp b/mlir/test/lib/Dialect/Test/TestPatterns.cpp
index f8b5144..ee4fa39 100644
--- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp
+++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp
@@ -70,6 +70,16 @@ static Attribute opMTest(PatternRewriter &rewriter, Value val) {
return rewriter.getIntegerAttr(rewriter.getIntegerType(32), i);
}
+static bool assertBinOpEqualArgsAndReturnTrue(Value v) {
+ Operation *operation = v.getDefiningOp();
+ if (operation->getOperand(0) != operation->getOperand(1)) {
+ // Name binding equality check must happen before user-defined constraints,
+ // thus this must not be triggered.
+ llvm::report_fatal_error("Arguments are not equal");
+ }
+ return true;
+}
+
namespace {
#include "TestPatterns.inc"
} // namespace