diff --git a/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp b/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp --- a/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp +++ b/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp @@ -67,6 +67,7 @@ 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 --- a/mlir/test/Transforms/sccp.mlir +++ b/mlir/test/Transforms/sccp.mlir @@ -216,3 +216,19 @@ 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 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -1244,6 +1244,18 @@ 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);