[mlir] SCCP add missing pessimistic setting
authorJacques Pienaar <jpienaar@google.com>
Tue, 26 Jul 2022 00:41:17 +0000 (17:41 -0700)
committerJacques Pienaar <jpienaar@google.com>
Tue, 26 Jul 2022 00:41:17 +0000 (17:41 -0700)
When this was updated in D127139 the update in-place case was no longer
marked as pessimistic. Add back in.

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

mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp
mlir/test/Transforms/sccp.mlir
mlir/test/lib/Dialect/Test/TestOps.td

index 386237e..657157a 100644 (file)
@@ -67,6 +67,7 @@ void SparseConstantPropagation::visitOperation(
   if (foldResults.empty()) {
     op->setOperands(originalOperands);
     op->setAttrs(originalAttrs);
+    markAllPessimisticFixpoint(results);
     return;
   }
 
index b18763a..490809f 100644 (file)
@@ -216,3 +216,19 @@ func.func @simple_produced_operand() -> (i32, i32) {
 
   return %arg1, %arg2 : i32, i32
 }
+
+// CHECK-LABEL: inplace_fold
+func.func @inplace_fold(%arg: i1) -> (i32) {
+  %0 = "test.op_in_place_fold_success"() : () -> i1
+  %1 = arith.constant 5 : i32
+  cf.cond_br %0, ^a, ^b
+
+^a:
+  // CHECK-NOT: addi
+  %3 = arith.addi %1, %1 : i32
+  return %3 : i32
+
+^b:
+  return %1 : i32
+}
+
index afc8df3..038f49a 100644 (file)
@@ -1244,6 +1244,18 @@ def TestOpInPlaceFold : TEST_Op<"op_in_place_fold"> {
   let hasFolder = 1;
 }
 
+// Test op that simply returns success.
+def TestOpInPlaceFoldSuccess : TEST_Op<"op_in_place_fold_success"> {
+  let results = (outs Variadic<I1>);
+  let hasFolder = 1;
+  let extraClassDefinition = [{
+    ::mlir::LogicalResult $cppClass::fold(ArrayRef<Attribute> operands,
+        SmallVectorImpl<OpFoldResult> &results) {
+      return success();
+    }
+  }];
+}
+
 // An op that always fold itself.
 def TestPassthroughFold : TEST_Op<"passthrough_fold"> {
   let arguments = (ins AnyType:$op);