@@ -315,6 +315,7 @@ TEST(OperandStorageTest, PopulateDefaultAttrs) {
315
315
TEST (OperationEquivalenceTest, HashWorksWithFlags) {
316
316
MLIRContext context;
317
317
context.getOrLoadDialect <test::TestDialect>();
318
+ OpBuilder b (&context);
318
319
319
320
auto *op1 = createOp (&context);
320
321
// `op1` has an unknown loc.
@@ -325,12 +326,36 @@ TEST(OperationEquivalenceTest, HashWorksWithFlags) {
325
326
op, OperationEquivalence::ignoreHashValue,
326
327
OperationEquivalence::ignoreHashValue, flags);
327
328
};
329
+ // Check ignore location.
328
330
EXPECT_EQ (getHash (op1, OperationEquivalence::IgnoreLocations),
329
331
getHash (op2, OperationEquivalence::IgnoreLocations));
330
332
EXPECT_NE (getHash (op1, OperationEquivalence::None),
331
333
getHash (op2, OperationEquivalence::None));
334
+ op1->setLoc (NameLoc::get (StringAttr::get (&context, " foo" )));
335
+ // Check ignore discardable dictionary attributes.
336
+ SmallVector<NamedAttribute> newAttrs = {
337
+ b.getNamedAttr (" foo" , b.getStringAttr (" f" ))};
338
+ op1->setAttrs (newAttrs);
339
+ EXPECT_EQ (getHash (op1, OperationEquivalence::IgnoreDiscardableAttrs),
340
+ getHash (op2, OperationEquivalence::IgnoreDiscardableAttrs));
341
+ EXPECT_NE (getHash (op1, OperationEquivalence::None),
342
+ getHash (op2, OperationEquivalence::None));
332
343
op1->destroy ();
333
344
op2->destroy ();
345
+
346
+ // Check ignore properties.
347
+ auto req1 = b.getI32IntegerAttr (10 );
348
+ Operation *opWithProperty1 = b.create <test::OpAttrMatch1>(
349
+ b.getUnknownLoc (), req1, nullptr , nullptr , req1);
350
+ auto req2 = b.getI32IntegerAttr (60 );
351
+ Operation *opWithProperty2 = b.create <test::OpAttrMatch1>(
352
+ b.getUnknownLoc (), req2, nullptr , nullptr , req2);
353
+ EXPECT_NE (getHash (op1, OperationEquivalence::None),
354
+ getHash (op2, OperationEquivalence::None));
355
+ EXPECT_EQ (getHash (opWithProperty1, OperationEquivalence::IgnoreProperties),
356
+ getHash (opWithProperty2, OperationEquivalence::IgnoreProperties));
357
+ opWithProperty1->destroy ();
358
+ opWithProperty2->destroy ();
334
359
}
335
360
336
361
} // namespace
0 commit comments