[mlir] Assume terminators in nested regions are always legal in FuncBufferizePass
authorButygin <ivan.butygin@intel.com>
Sat, 10 Apr 2021 16:38:11 +0000 (19:38 +0300)
committerButygin <ivan.butygin@intel.com>
Wed, 21 Apr 2021 08:55:11 +0000 (11:55 +0300)
Previously, any terminator without ReturnLike and BranchOpInterface traits (e.g. scf.condition) were causing pass to fail.

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

mlir/lib/Dialect/StandardOps/Transforms/FuncConversions.cpp
mlir/test/Dialect/Standard/func-bufferize.mlir

index 218efac..49aaade 100644 (file)
@@ -164,5 +164,10 @@ bool mlir::isNotBranchOpInterfaceOrReturnLikeOp(Operation *op) {
   if (!block || &block->back() != op)
     return true;
 
+  // We don't want to handle terminators in nested regions, assume they are
+  // always legal.
+  if (!isa_and_nonnull<FuncOp>(op->getParentOp()))
+    return true;
+
   return false;
 }
index e4d6a8c..ba4710c 100644 (file)
@@ -67,3 +67,25 @@ func @unable_to_update_terminator(%arg0: tensor<f32>) -> tensor<f32> {
   ^bb2(%bbarg1: tensor<f32>):
     return %bbarg1 : tensor<f32>
 }
+
+// -----
+
+// There was a bug in func-bufferize pass which caused terminators without
+// ReturnLike and BranchOpInterface traits (e.g. scf.condition) to always
+// fail to legalize even if bufferization doesn't needed.
+// Check the pass succedeed.
+// CHECK: bufferize_while
+// CHECK: scf.while
+// CHECK: scf.condition
+func @bufferize_while(%arg0: i64, %arg1: i64) -> i64 {
+  %c2_i64 = constant 2 : i64
+  %0:2 = scf.while (%arg2 = %arg0) : (i64) -> (i64, i64) {
+    %1 = cmpi slt, %arg2, %arg1 : i64
+    scf.condition(%1) %arg2, %arg2 : i64, i64
+  } do {
+  ^bb0(%arg2: i64, %arg3: i64):
+    %1 = muli %arg3, %c2_i64 : i64
+    scf.yield %1 : i64
+  }
+  return %0#1 : i64
+}