[Mlir-commits] [mlir] c096377 - Fixed a failure when const matcher fails, added a test to catch

Rob Suderman llvmlistbot at llvm.org
Fri Oct 16 15:03:17 PDT 2020


Author: Rob Suderman
Date: 2020-10-16T15:02:24-07:00
New Revision: c096377905db8144ed310247609134783b2c9b73

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

LOG: Fixed a failure when const matcher fails, added a test to catch

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

Added: 
    

Modified: 
    mlir/test/mlir-tblgen/pattern.mlir
    mlir/tools/mlir-tblgen/RewriterGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/mlir-tblgen/pattern.mlir b/mlir/test/mlir-tblgen/pattern.mlir
index 616e116cb170..a1ae18c05b3d 100644
--- a/mlir/test/mlir-tblgen/pattern.mlir
+++ b/mlir/test/mlir-tblgen/pattern.mlir
@@ -285,6 +285,7 @@ func @testConstOpReplaced() -> (i32) {
   // CHECK: [[V0]]
   return %2 : i32
 }
+
 // CHECK-LABEL: testConstOpMatchFailure
 func @testConstOpMatchFailure() -> (i64) {
   // CHECK-DAG: [[C0:%.+]] = constant 1
@@ -300,6 +301,20 @@ func @testConstOpMatchFailure() -> (i64) {
   return %2 : i64
 }
 
+// CHECK-LABEL: testConstOpMatchNonConst
+func @testConstOpMatchNonConst(%arg0 : i32) -> (i32) {
+  // CHECK-DAG: [[C0:%.+]] = constant 1
+  %0 = "test.constant"() {value = 1 : i32} : () -> i32
+
+  // CHECK: [[V0:%.+]] = "test.op_r"([[C0]], %arg0)
+  %1 = "test.op_r"(%0, %arg0) : (i32, i32) -> i32
+
+  // CHECK: [[V0]]
+  return %1 : i32
+}
+
+
+
 //===----------------------------------------------------------------------===//
 // Test Enum Attributes
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp
index 5521eea38252..2e0e9abe341e 100644
--- a/mlir/tools/mlir-tblgen/RewriterGen.cpp
+++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp
@@ -259,6 +259,7 @@ void PatternEmitter::emitNativeCodeMatch(DagNode tree, StringRef opName,
 
   raw_indented_ostream::DelimitedScope scope(os);
 
+  os << "if(!" << opName << ") return failure();\n";
   for (int i = 0, e = tree.getNumArgs(); i != e; ++i) {
     std::string argName = formatv("arg{0}_{1}", depth, i);
     if (DagNode argTree = tree.getArgAsNestedDag(i)) {


        


More information about the Mlir-commits mailing list