From 13bc82b5873a234cb8f2af050a093b6710dbe17a Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Mon, 25 Jul 2022 17:41:17 -0700 Subject: [PATCH] [mlir] SCCP add missing pessimistic setting 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 --- .../Analysis/DataFlow/ConstantPropagationAnalysis.cpp | 1 + mlir/test/Transforms/sccp.mlir | 16 ++++++++++++++++ mlir/test/lib/Dialect/Test/TestOps.td | 12 ++++++++++++ 3 files changed, 29 insertions(+) diff --git a/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp b/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp index 386237e..657157a 100644 --- a/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp +++ b/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp @@ -67,6 +67,7 @@ void SparseConstantPropagation::visitOperation( if (foldResults.empty()) { op->setOperands(originalOperands); op->setAttrs(originalAttrs); + markAllPessimisticFixpoint(results); return; } diff --git a/mlir/test/Transforms/sccp.mlir b/mlir/test/Transforms/sccp.mlir index b18763a..490809f 100644 --- a/mlir/test/Transforms/sccp.mlir +++ b/mlir/test/Transforms/sccp.mlir @@ -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 +} + diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index afc8df3..038f49a 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -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); + let hasFolder = 1; + let extraClassDefinition = [{ + ::mlir::LogicalResult $cppClass::fold(ArrayRef operands, + SmallVectorImpl &results) { + return success(); + } + }]; +} + // An op that always fold itself. def TestPassthroughFold : TEST_Op<"passthrough_fold"> { let arguments = (ins AnyType:$op); -- 2.7.4