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
+}
+
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);