@@ -907,6 +907,22 @@ struct TestPassthroughInvalidOp : public ConversionPattern {
907
907
return success ();
908
908
}
909
909
};
910
+ // / Replace with valid op, but simply drop the operands. This is used in a
911
+ // / regression where we used to generate circular unrealized_conversion_cast
912
+ // / ops.
913
+ struct TestDropAndReplaceInvalidOp : public ConversionPattern {
914
+ TestDropAndReplaceInvalidOp (MLIRContext *ctx, const TypeConverter &converter)
915
+ : ConversionPattern(converter,
916
+ " test.drop_operands_and_replace_with_valid" , 1 , ctx) {
917
+ }
918
+ LogicalResult
919
+ matchAndRewrite (Operation *op, ArrayRef<Value> operands,
920
+ ConversionPatternRewriter &rewriter) const final {
921
+ rewriter.replaceOpWithNewOp <TestValidOp>(op, std::nullopt, ValueRange (),
922
+ std::nullopt);
923
+ return success ();
924
+ }
925
+ };
910
926
// / This pattern handles the case of a split return value.
911
927
struct TestSplitReturnType : public ConversionPattern {
912
928
TestSplitReturnType (MLIRContext *ctx)
@@ -1070,6 +1086,19 @@ struct TestCreateUnregisteredOp : public OpRewritePattern<ILLegalOpG> {
1070
1086
return success ();
1071
1087
};
1072
1088
};
1089
+
1090
+ class TestEraseOp : public ConversionPattern {
1091
+ public:
1092
+ TestEraseOp (MLIRContext *ctx) : ConversionPattern(" test.erase_op" , 1 , ctx) {}
1093
+ LogicalResult
1094
+ matchAndRewrite (Operation *op, ArrayRef<Value> operands,
1095
+ ConversionPatternRewriter &rewriter) const final {
1096
+ // Erase op without replacements.
1097
+ rewriter.eraseOp (op);
1098
+ return success ();
1099
+ }
1100
+ };
1101
+
1073
1102
} // namespace
1074
1103
1075
1104
namespace {
@@ -1148,8 +1177,9 @@ struct TestLegalizePatternDriver
1148
1177
TestUpdateConsumerType, TestNonRootReplacement,
1149
1178
TestBoundedRecursiveRewrite, TestNestedOpCreationUndoRewrite,
1150
1179
TestReplaceEraseOp, TestCreateUnregisteredOp, TestUndoMoveOpBefore,
1151
- TestUndoPropertiesModification>(&getContext ());
1152
- patterns.add <TestDropOpSignatureConversion>(&getContext (), converter);
1180
+ TestUndoPropertiesModification, TestEraseOp>(&getContext ());
1181
+ patterns.add <TestDropOpSignatureConversion, TestDropAndReplaceInvalidOp>(
1182
+ &getContext (), converter);
1153
1183
mlir::populateAnyFunctionOpInterfaceTypeConversionPattern (patterns,
1154
1184
converter);
1155
1185
mlir::populateCallOpTypeConversionPattern (patterns, converter);
0 commit comments