[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 386237e47b5e7fea4978bfc770844a7fc987f891..657157a5664f4ca7048094e9f6ea9bf051b156fc 100644 (file)
@@ -67,6 +67,7 @@ void SparseConstantPropagation::visitOperation(
   if (foldResults.empty()) {
     op->setOperands(originalOperands);
     op->setAttrs(originalAttrs);
+    markAllPessimisticFixpoint(results);
     return;
   }
 
index b18763ad1ee4ca0ed3d9d67f117dc53d5eb970da..490809fd5d7d745dc4995dd664959842ee9d54c4 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 afc8df3b276c279b5d44879d5d2b55f5b0739749..038f49aeed456b6f0100c727bbd29321f4c9aa89 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);